# you'll need RGoogleDocs (with RCurl dependency..)
install.packages("RGoogleDocs", repos = "http://www.omegahat.org/R", type="source")
library(RGoogleDocs)
gpasswd = "mysecretpassword"
auth = getGoogleAuth("kay.cichini@gmail.com", gpasswd)
con = getGoogleDocsConnection(auth)
CAINFO = paste(system.file(package="RCurl"), "/CurlSSL/ca-bundle.crt", sep = "")
docs <- getDocs(con, cainfo = CAINFO)
# get file references
hrefs <- lapply(docs, function(x) return(x@access["href"]))
keys <- sub(".*/full/.*%3A(.*)", "\\1", hrefs)
types <- sub(".*/full/(.*)%3A.*", "\\1", hrefs)
# make urls (for url-scheme see: http://techathlon.com/download-shared-files-google-drive/)
# put format parameter for other output formats!
pdf_urls <- paste0("https://docs.google.com/uc?export=download&id=", keys)
doc_urls <- paste0("https://docs.google.com/document/d/", keys, "/export?format=", "txt")
# download documents with your browser
gdoc_ids <- grep("document", types)
lapply(gdoc_ids, function(x) shell.exec(doc_urls[x]))
pdf_ids <- grep("pdf", types, ignore.case = T)
lapply(pdf_ids, function(x) shell.exec(pdf_urls[x]))
17 Mar 2014
Download all Documents from Google Drive with R
A commentator on my blog recently asked if it is possible to retrieve all direct links to your Google Documents. And indeed it can be very easily done with R, just like so:
12 Apr 2013
Download File from Google Drive/Docs Programmatically with R
Following up my lattest posting on how to download files from the cloud with R..
dl_from_GoogleD <- function(output, key, format) {
## Arguments:
## output = output file name
## key = Google document key
## format = output format (pdf, rtf, doc, txt..)
## Note: File must be shareable!
require(RCurl)
bin <- getBinaryURL(paste0("https://docs.google.com/document/d/", key, "/export?format=", format),
ssl.verifypeer = FALSE)
con <- file(output, open = "wb")
writeBin(bin, con)
close(con)
message(noquote(paste(output, "read into", getwd())))
}
# Example:
dl_from_GoogleD(output = "dl_test.pdf",
key = "1DdauvkcVm5XtRBkQIv1na8PeLAwpCBdW8pALCFpRWeM",
format = "pdf")
shell.exec("dl_test.pdf")
EDIT:
Here's how it can be done for spreadsheet-like data, like HERE, which is a comma seperated file with .txt extension saved to Google Drive. See also this post
library(RCurl)
setwd(tempdir())
destfile = "test_google_docs.csv"
x = getBinaryURL("https://docs.google.com/uc?export=download&id=0B2wAunwURQNsR0I0a0NlQUlJdzA", followlocation = TRUE, ssl.verifypeer = FALSE)
writeBin(x, destfile, useBytes = TRUE)
shell.exec(paste(tempdir(), "/test_google_docs.csv", sep = ""))
5 Apr 2013
Embedding Google Docs and Google Viewer
..Here's a short example of the usage of the Google Viewer and Google Docs embeds (see here). If you want to embed a view of any file on Google Drive/Docs you can do this by putting a pdf preview (the file could be in any format, see first example, which is a Google text document) in an iframe or, in the case of spreadsheets, the speradsheet itself into an iframe.
The second embed below shows the latest outcome of an online questionnaire and in the speradsheet that holds the result the new answers to the questoinnaire are updated every 5 minutes after refreshing the view. So, you can, i.e., make an online questoinnaire with a Google form and display the results like below. With a little tweaking of the parameters, which I obviously haven't done yet, the result would of course be more visually appealing.
If you try for one of your files you just need to replace the id/key in the URL..
The Result:
The second embed below shows the latest outcome of an online questionnaire and in the speradsheet that holds the result the new answers to the questoinnaire are updated every 5 minutes after refreshing the view. So, you can, i.e., make an online questoinnaire with a Google form and display the results like below. With a little tweaking of the parameters, which I obviously haven't done yet, the result would of course be more visually appealing.
If you try for one of your files you just need to replace the id/key in the URL..
The Result:
2 May 2012
Playing with knitr: Create Report with Dynamic List
Here is a little toy example using knitr, LaTeX/MiKTeX and Google Docs.
Say you had a list on Google Docs (say a list of attendants) and you want to print a report with it..
Then see this example using this Rnw-file and the output...
make the tex-file with:
or with this shortcut:
Say you had a list on Google Docs (say a list of attendants) and you want to print a report with it..
Then see this example using this Rnw-file and the output...
make the tex-file with:
library(knitr)
knit("knitr_list_of_attendants.Rnw")
..then compile the tex-file with MiKTeX.or with this shortcut:
knit2pdf("knitr_list_of_attendants.Rnw")
browseURL("knitr_list_of_attendants.pdf")
13 Mar 2012
R-Function to Read Data from Google Docs Spreadsheets
14 Nov 2011
How to Download and Run Google Docs Script in the R Console
...There is not much to it:
upload a txt file with your script, share it for anyone with the link, then simply run something like the below code.
ps: When using the code for your own purpose mind to change "https" to "http" and to insert your individual document id.
pss: You could use download.file() in this way for downloading any file from Google Docs..
pss: You could use download.file() in this way for downloading any file from Google Docs..
12 Oct 2011
How to Link to Files at Google Docs for Direct Download
...Google doesn't tell you this, as far as I know - so, if you want to link to a file at Google Docs for direct download you can use the following address scheme:
https://docs.google.com/uc?export=download&id=YourIndividualID
You can copy your individual file id from within the "Share..."-dialogue. Here you also need to put the share settings to "public" or to "anyone with the link"
a HTML example for this link to a pdf-file:
https://docs.google.com/uc?export=download&id=YourIndividualID
You can copy your individual file id from within the "Share..."-dialogue. Here you also need to put the share settings to "public" or to "anyone with the link"
a HTML example for this link to a pdf-file:
Subscribe to:
Comments
(
Atom
)



