Learn R Programming

mosaic (version 0.4-1)

fetchGoogle: Fetch data from a web service

Description

Read a data set generated from a web service such as Google Docs.

Usage

fetchGoogle(URL, key = NULL)

Arguments

URL
the URL to retrieve a CSV file from the service
key
for convenience, just the "key" part of the Google link

Details

Web services such as Google Docs allow you to store spreadsheets "in the cloud". By setting permissions in the service, you can arrange to make the data set public, so that anyone with an appropriate URL can access the data. Reading such data into R can be done simply if the service supports exporting the data in a CSV format via URL link. For instance, Google Spreadsheets can be set up to publish a spreadsheet via a URL. Unfortunately, the read.csv() function, although able to read URLs pointing to a file, cannot handle the protocol needed to talk to services such as Google Docs. fetchGoogle() allows you to do this. fetchGoogle() derives its functionality from the RCurl package, which must be installed for the function to work. RCurl will be loaded automatically if it is installed. Generating the URL from the web service will, of course, depend on how that service is set up. For Google Spreadsheets, you, the owner of a spreadsheet, can (1) open the spreadsheet in a browser (2) select the File/Publish to the Web menu item (3) in the resulting dialog box, press "Start publishing" (4) under "Get a link to the published data", select CSV format (5) copy the https://docs.google.com/spreadsheet/pub?... link and post it where your users can get to it.

Examples

Run this code
s = fetchGoogle("https://spreadsheets.google.com/spreadsheet/pub?hl=en&hl=en&key=0Am13enSalO74dEVzMGJSMU5TbTc2eWlWakppQlpjcGc&single=TRUE&gid=0&output=csv")
s = fetchGoogle(key="0Am13enSalO74dEVzMGJSMU5TbTc2eWlWakppQlpjcGc")

Run the code above in your browser using DataLab