Import of tabular data

Import of a tab-delimited tabular file

myDF <- read.delim("myData.xls", sep="\t")

Import of Excel file. Note: working with tab- or comma-delimited files is more flexible and preferred.

myDF <- read.xls"myData.xls")

Import of Google Sheets. The following example imports a sample Google Sheet from here. Detailed instructions for interacting from R with Google Sheets with the required googlesheets package are here.

library("googlesheets"); library("dplyr"); library(knitr)
gs_auth() # Creates authorizaton token (.httr-oauth) in current directory if not present
sheetid <-"1U-32UcwZP1k3saKeaH1mbvEAOfZRdNHNkWK2GI1rpPM"
gap <- gs_key(sheetid)
mysheet <- gs_read(gap, skip=4)
myDF <-

Export of tabular data

write.table(myDF, file="myfile.xls", sep="\t", quote=FALSE, col.names=NA)

Line-wise import

myDF <- readLines("myData.txt")

Line-wise export

writeLines(, "myData.txt")

Copy and paste into R

On Windows/Linux systems


On Mac OS X systems


Copy and paste from R

On Windows/Linux systems

write.table(iris, "clipboard", sep="\t", col.names=NA, quote=F) 

On Mac OS X systems

zz <- pipe('pbcopy', 'w')
write.table(iris, zz, sep="\t", col.names=NA, quote=F)

Homework 3A

Homework 3A: Object Subsetting Routines and Import/Export