It's helpful to be able to collaborate in collecting data. Google spreadsheets is a useful tool for this.
For those implementations of R that support the web protocol used by Google, there is a simple way to read Google spreadsheets into R via the fetchGoogle
function in the mosaic package. Otherwise, there is a multi-step process that is not too difficult.
Check whether the RCurl
package is installed on your system. If it is, then you're good to go with the fetchGoogle
method. The RCurl
installed. The
If you are running R on your own desktop rather than using a server, try installing RCurl
. On many systems, it is very easy; on others it is not possible unless you have some detailed knowledge of how to install command-line software.
fetchGoogle
(See below for how to read Google spreadsheets without fetchGoogle
.)
You will have to set up your spreadsheet on Google to talk with R. This is a one-time operation that will continue to work even if you add more data to the spreadsheet.
Now, to R …
1. Make sure you have the mosaic package running: require(mosaic)
1. Paste the link from step (5) into R as a quoted argument to fetchGoogle()
command, like this
mydat = fetchGoogle("https://docs.google.com/spreadsheet/pub?key=0Am13enSalO74dEtyWGxpWWFsN3Z0OUlZNG5xYmRVWWc&single=true&gid=0&output=csv")
You can email this command to your collaborators. You may find it convenient to use the history command (searching on “fetchGoogle”) to find the command again when you need it.
RCurl
Unfortunately, the particular web protocol used by Google spreadsheets is not yet available in all implementations of R. Until it is, here are the several steps to read a Google spreadsheet into R. (If you're running a desktop version of R, check out the section “If you can install RCurl…”)
fetchData()
to read in the spreadsheet you have just saved. When given an empty argument, fetchData()
will bring up a file browser which you can use to navigate to the file you just saved. BUT …fetchData()
with an empty argument and navigate to the file you have just uploaded to the RStudio server.This is a pain, I know.