Export your data from R’

R’ and RStudio are great but sometimes it’s better the just export your data to exploit them elsewhere or just show them to other people. Here is a review of possible techniques:

Export your data into a CSV

assuming your data is store inside df var, fairly simple:

1

2

3

4

#setup where to write the file

setwd("~/Desktop")

# en write the file

write.csv(df,"data.csv")

Export your data into an excel file

A little bit more complex, we’ll use the ‘xlsx’ package

1

2

3

4

5

6

7

8

9

10

11

#setup where to write the file

setwd("~/Desktop")

# if the package is not instal yet, run this

# install.packages("xlsx")

# Loading the package

library(xlsx)

# we write the file

write.xlsx(df,"data.xlsx")

A few more tips for you:

I’ll like to use the sheetName option to explicitly name the tab. The default name is “Sheet1”. Quite useful to have a record of when the file has been generated for example. Replace last instruction what follows and you’ll be able to know.

1

write.xlsx(df,"data.xlsx",sheetName=format(Sys.Date(),"%d %b %Y"))

Another good one that I like is to send the excel file to a Shared folder directly. Replace first instruction by

1

setwd("/Users/me/Dropbox/Public")

Of course, replace the file path by yours.

Send your data by email

If the data to send it not to big, another interesting idea is to send it by email using the ‘gmailr’ package.