Cookies help us display personalized product recommendations and ensure you have great shopping experience.

By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
SmartData CollectiveSmartData Collective
  • Analytics
    AnalyticsShow More
    data analytics and truck accident claims
    How Data Analytics Reduces Truck Accidents and Speeds Up Claims
    7 Min Read
    predictive analytics for interior designers
    Interior Designers Boost Profits with Predictive Analytics
    8 Min Read
    image fx (67)
    Improving LinkedIn Ad Strategies with Data Analytics
    9 Min Read
    big data and remote work
    Data Helps Speech-Language Pathologists Deliver Better Results
    6 Min Read
    data driven insights
    How Data-Driven Insights Are Addressing Gaps in Patient Communication and Equity
    8 Min Read
  • Big Data
  • BI
  • Exclusive
  • IT
  • Marketing
  • Software
Search
© 2008-25 SmartData Collective. All Rights Reserved.
Reading: How to use a Google Spreadsheet as data in R
Share
Notification
Font ResizerAa
SmartData CollectiveSmartData Collective
Font ResizerAa
Search
  • About
  • Help
  • Privacy
Follow US
© 2008-23 SmartData Collective. All Rights Reserved.
SmartData Collective > Uncategorized > How to use a Google Spreadsheet as data in R
Uncategorized

How to use a Google Spreadsheet as data in R

DavidMSmith
DavidMSmith
6 Min Read
SHARE

One of the great strengths of R is that it promotes reproducible research: as an open-source system, you can easily send a script file to a colleague with the confidence that they’ll be able to get the same results using R on their own system. Provided they have the same data, that is. If that’s your goal, you can always send along a data file, but that can add some complications. You have to take care with the filenames in your script, and dealing with data that changes regularly can be annoying.

Google Docs offers a solution. As long as you have a Google account, you can store your data as a Google Spreadsheet, and then create a special URL for that spreadsheet that can be used as a CSV file source by R. The process is a bit complex, but it only needs to be done once, and then your data are freely available to anyone who wants to access it via R. 

First, change the permissions for your spreadsheet on the main Google Docs page (the one that lists all of your Google Documents: spreadsheets, documents, presentations, etc) and configure your spreadsheet so that it can be viewed by everyone. (I’m not sure if this is strictly necessary for the export, but it does give your …

More Read

Big Data Will Make IT the New Intel Inside
Reflecting on Times Open
Searching SPSS Case Data: An Enhancement to the SPSSINC PROCESS FILES Extension Command
Coca-Cola’s New Marketing Map: Is It Better?
A Step Towards Protecting Net Neutrality



One of the great strengths of R is that it promotes reproducible research: as an open-source system, you can easily send a script file to a colleague with the confidence that they’ll be able to get the same results using R on their own system. Provided they have the same data, that is. If that’s your goal, you can always send along a data file, but that can add some complications. You have to take care with the filenames in your script, and dealing with data that changes regularly can be annoying.

Google Docs offers a solution. As long as you have a Google account, you can store your data as a Google Spreadsheet, and then create a special URL for that spreadsheet that can be used as a CSV file source by R. The process is a bit complex, but it only needs to be done once, and then your data are freely available to anyone who wants to access it via R. 

First, change the permissions for your spreadsheet on the main Google Docs page (the one that lists all of your Google Documents: spreadsheets, documents, presentations, etc) and configure your spreadsheet so that it can be viewed by everyone. (I’m not sure if this is strictly necessary for the export, but it does give your collaborators the ability to view the data directly as a spreadsheet.)

  • Select your spreadsheet in the Google Docs page by marking the checkbox next to its name.
  • Click the “Share” menu in the toolbar, and choose “See who has access…”
  • Click the People With Access Tab.
  • Next to “Sign-in is required to view this item,” click Change, and select “Let people view without signing in.”

Now anyone can view your spreadsheet in Google Docs using the link given in the “Share > Get the link to share…” menu. But we want a link for the CSV export version of the spreadsheet, not the spreadsheet itself. Here’s how to get that.

  • Open your spreadsheet in Google Docs.
  • Click the blue Share button (in the upper-right corner of the spreadsheet) and choose “Publish as a Web Page”.
  • For “Sheets to Publish” choose “All Sheets,” and check the box “Automatically republish when changes are made” if you want to dynamically update the data for R when you edit it.
  • Click “Start Publishing”. This will activate the options in the box “Get a link to the published data”, below.
  • Change the export type from “Web Page” to “CSV (comma-separated values)”.
  • Change “All sheets” to “Sheet1” (or select the sheet you want to export)
  • Change “All Cells” to the specific range you want to export, beginning with the header row. Use Excel-style notation, like “A1:C6” for the first 3 columns and the first 6 rows.
  • Click “Republish now.”

The Publish box should look something like this.

Spreadsheet export

You can now use the URL in the bottommost box above directly with read.csv in R:

> read.csv(“http://spreadsheets.google.com/pub?key=tCA0HtNtIlmhW-GLzFLLbZg
 &single=true&gid=0&range=A1%3AC6&output=csv”)

  x   y  z

1 1 0.3 10

2 2 0.5 14

3 3 1.1 12

4 4 0.1  1

5 5 1.9  0

Better yet, if I ever change the data in the Google spreadsheet, the command above will always retrieve the updated data (provided I chose the “Automatically republish” option, above).

I believe you can do something similar with the RGoogleDocs package (currently in beta and not yet on CRAN), but this process requires no additional packages for you or the recipient of your data. 

Link to original post

Share This Article
Facebook Pinterest LinkedIn
Share

Follow us on Facebook

Latest News

data analytics and truck accident claims
How Data Analytics Reduces Truck Accidents and Speeds Up Claims
Analytics Big Data Exclusive
predictive analytics for interior designers
Interior Designers Boost Profits with Predictive Analytics
Analytics Exclusive Predictive Analytics
big data and cybercrime
Stopping Lateral Movement in a Data-Heavy, Edge-First World
Big Data Exclusive
AI and data mining
What the Rise of AI Web Scrapers Means for Data Teams
Artificial Intelligence Big Data Exclusive

Stay Connected

1.2kFollowersLike
33.7kFollowersFollow
222FollowersPin

You Might also Like

SOA adoption trends — what the data tells us

1 Min Read

Spam in the Twitterverse

5 Min Read
Image
Uncategorized

Will Hyperscale Networking Shake Up the Data Center?

4 Min Read

Analogue Business with a Digital Facade

8 Min Read

SmartData Collective is one of the largest & trusted community covering technical content about Big Data, BI, Cloud, Analytics, Artificial Intelligence, IoT & more.

data-driven web design
5 Great Tips for Using Data Analytics for Website UX
Big Data
ai is improving the safety of cars
From Bolts to Bots: How AI Is Fortifying the Automotive Industry
Artificial Intelligence

Quick Link

  • About
  • Contact
  • Privacy
Follow US
© 2008-25 SmartData Collective. All Rights Reserved.
Go to mobile version
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?