Is there a way to read columns with strings as strings when using RGoogleDocs
-
06-07-2021 - |
Question
I use RGoogleDocs a lot. I use it to read in data that is private or only shared with a few people. I know that read.table
and read.csv
allow one to use stringsAsFactors=FALSE
.
I want to do something similar in RGoogleDocs. Here is my typical code
sheets.con <- getGoogleDocsConnection(getGoogleAuth("fjb@gmail.com", ps, service ="wise"))
spreadsheet <- getWorksheets("private spreadsheet",sheets.con)
first <- sheetAsMatrix(spreadsheet$"Sheet 1",header=TRUE, as.data.frame=TRUE, trim=TRUE) #Get one sheet
That almost always reads the character values as factors. I have been using data.table a lot lately and factors seem to make my data munging in data.table a bit bothersome. Is there an easy way to read the non-numeric columns as character vectors rather than as factors?
La solution
Duncan Temple Lang, the writer of RGoogleDocs updated the package to 0.7-0. He added stringsAsFactors
to the getWorksheets()
and sheetAsMatrix()
function.
Here is how you can get it into your R.
install.packages("devtools")
library(devtools)
install_github("RGoogleDocs", "duncantl")
Now my line is
first <- sheetAsMatrix(spreadsheet$"Sheet 1",header=TRUE, as.data.frame=TRUE, trim=TRUE, stringsAsFactors=FALSE) #Get one sheet