
Convenience function to read spreadsheet-like files
Source:R/read_spreadsheet.R
read_spreadsheet.Rd
Currently reads spreadsheets from Google Sheets or from xlsx
, csv
,
or sav
files.
Arguments
- x
The URL or path to a file.
- sheet
Optionally, the name(s) of the worksheet(s) to select.
- columnDictionary
Optionally, a dictionary with column names to check for presence. A named list of vectors.
- localBackup
If not
NULL
, a valid filename to write a local backup to.- exportGoogleSheet
If
x
is a URL to a Google Sheet, instead of using thegooglesheets4
package to download the data, by passingexportGoogleSheet=TRUE
, an export link will be produced and the data will be downloaded as Excel spreadsheet.- flattenSingleDf
Whether to return the result as a data frame if only one data frame is returned as a result.
- xlsxPkg
Which package to use to work with Excel spreadsheets.
- failQuietly
Whether to give an error when
x
is not a valid URL or existing file, or just returnNULL
invisibly.- silent
Whether to be silent or chatty.
Value
A list of dataframes, or, if only one data frame was loaded and
flattenSingleDf
is TRUE
, a data frame.
Examples
### Note that this will require an active
### internet connection! This if statement
### checks for that.
# \donttest{
if (tryCatch({readLines("https://google.com",n=1); TRUE}, error=function(x) FALSE)) {
### Read the example ROCK codebook
ROCK_codebook <-
read_spreadsheet(
paste0(
"https://docs.google.com/spreadsheets/d/",
"1gVx5uhYzqcTH6Jq7AYmsLvHSBaYaT-23c7ZhZF4jmps"
)
);
### Show a bit
ROCK_codebook$metadata[1:3, ];
}
#> ✔ Reading from rock-codebook-spec.
#> ✔ Range ''metadata''.
#> ✔ Reading from rock-codebook-spec.
#> ✔ Range ''codes''.
#> ✔ Reading from rock-codebook-spec.
#> ✔ Range ''examples''.
#> ✔ Reading from rock-codebook-spec.
#> ✔ Range ''aesthetics''.
#> ✔ Reading from rock-codebook-spec.
#> ✔ Range ''relationships''.
#> field content
#> 1 title An example of an initial code book for a study into sleeping patterns
#> 2 author E. G. X. Ample
#> 3 date 1641081600
# }