Title: | Download Google Sheets Using Just the URL |
---|---|
Description: | Simple package to download Google Sheets using just the sharing link. Spreadsheets can be downloaded as a data frame, or as plain text to parse manually. Google Sheets is the new name for Google Docs Spreadsheets <https://www.google.com/sheets/about>. |
Authors: | Max Conway [aut, cre] |
Maintainer: | Max Conway <[email protected]> |
License: | GPL-3 |
Version: | 0.4.5 |
Built: | 2024-11-22 03:20:39 UTC |
Source: | https://github.com/maxconway/gsheet |
Converts the viewing url for a google sheet to a download url.
construct_download_url(url, format = "csv", sheetid = NULL)
construct_download_url(url, format = "csv", sheetid = NULL)
url |
the google sheet url |
format |
controls the column separator used. |
sheetid |
the id of the sheet to download from. (Default |
# Download a sheet manually using readr url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo' if(requireNamespace('readr', quietly=TRUE)){ library(readr) read_csv(construct_download_url(url), col_types = cols( mpg = col_double(), cyl = col_integer(), disp = col_double(), hp = col_integer(), drat = col_double(), wt = col_double(), qsec = col_double(), vs = col_integer(), am = col_integer(), gear = col_integer(), carb = col_integer() )) }
# Download a sheet manually using readr url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo' if(requireNamespace('readr', quietly=TRUE)){ library(readr) read_csv(construct_download_url(url), col_types = cols( mpg = col_double(), cyl = col_integer(), disp = col_double(), hp = col_integer(), drat = col_double(), wt = col_double(), qsec = col_double(), vs = col_integer(), am = col_integer(), gear = col_integer(), carb = col_integer() )) }
This is a convenience function, designed to download a table quickly and conveniently. If you experience any unexpected results, or you want more reliability or control (e.g. for a production situation), then I'd recommend you parse manually using one of the constructions in the examples:
read.csv(text=gsheet2text(url, format='csv'), stringsAsFactors=FALSE)
gsheet2tbl(url, sheetid = NULL)
gsheet2tbl(url, sheetid = NULL)
url |
the google sheet url |
sheetid |
the index of the sheet to be downloaded. If you use the direct sheet URL, rather than the share by link, this will automatically be extracted. Otherwise, the first sheet will be downloaded by default. |
The Google sheet must have 'share by link' turned on.
If the package readr
is available, then it will be used.
This can produce slightly different, but normally better, parsings.
gsheet2text
to download as plain text
# Download a sheet url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo' a <- gsheet2tbl(url) # Download the second sheet, using the direct url url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo#gid=850032961' b <- gsheet2tbl(url) # To download a sheet with more control, use the following: url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo' read.csv(text=gsheet2text(url, format='csv'), stringsAsFactors=FALSE) # Or, with readr: if(requireNamespace('readr', quietly=TRUE)){ library(readr) read_csv(construct_download_url(url), col_types = cols( mpg = col_double(), cyl = col_integer(), disp = col_double(), hp = col_integer(), drat = col_double(), wt = col_double(), qsec = col_double(), vs = col_integer(), am = col_integer(), gear = col_integer(), carb = col_integer() )) }
# Download a sheet url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo' a <- gsheet2tbl(url) # Download the second sheet, using the direct url url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo#gid=850032961' b <- gsheet2tbl(url) # To download a sheet with more control, use the following: url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo' read.csv(text=gsheet2text(url, format='csv'), stringsAsFactors=FALSE) # Or, with readr: if(requireNamespace('readr', quietly=TRUE)){ library(readr) read_csv(construct_download_url(url), col_types = cols( mpg = col_double(), cyl = col_integer(), disp = col_double(), hp = col_integer(), drat = col_double(), wt = col_double(), qsec = col_double(), vs = col_integer(), am = col_integer(), gear = col_integer(), carb = col_integer() )) }
Downloads a Google sheet as text, using just the url. The Google sheet must have 'share by link' turned on.
gsheet2text(url, format = "csv", sheetid = NULL)
gsheet2text(url, format = "csv", sheetid = NULL)
url |
the google sheet url |
format |
controls the column separator used. |
sheetid |
the id of the sheet to download from. (Default |
sheetid
is the index of the sheet to be downloaded.
If you use the direct sheet URL, rather than the share by link, this will automatically be extracted.
Otherwise, the first sheet will be downloaded by default.
gsheet2text
to download as a table
url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo' a <- gsheet2text(url) b <- read.csv(text=a)
url <- 'docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo' a <- gsheet2text(url) b <- read.csv(text=a)