Created
March 13, 2012 13:30
-
-
Save gimoya/2028759 to your computer and use it in GitHub Desktop.
Read spreadsheet data from Google Docs to R workspace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
google_ss <- function(gid = NA, key = NA) | |
{ | |
if (is.na(gid)) {stop("\nWorksheetnumber (gid) is missing\n")} | |
if (is.na(key)) {stop("\nDocumentkey (key) is missing\n")} | |
require(RCurl) | |
url <- getURL(paste("https://docs.google.com/spreadsheet/pub?key=", key, | |
"&single=true&gid=", gid, "&output=csv", sep = ""), | |
cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")) | |
read.csv(textConnection(url), header = T, sep = ",") | |
} | |
## Example: | |
## Mind that the worksheets are numbered consecutively from 0 to n, | |
## irrespective of the actual worksheet-name. | |
## The key should be put in apostrophes. | |
## And, the URL works only for published spreadsheets! | |
(data <- google_ss(gid = 0, | |
key = "0AmwAunwURQNsdDNpZzJqTU90cmpTU0sza2xLTW9fenc")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment