knitr::opts_chunk$set( collapse = TRUE, comment = "#>", error = TRUE )
The googledrive package makes some world-readable, persistent example files available on Google Drive, to use in examples and reprexes.
Local versions of those same example files also ship with the googledrive package, to make it easier to demo specific workflows that start with, e.g., drive_upload()
.
This article lists these assets and explains how to get at them.
Since the remote example files are accessible to all, after we attach googledrive, we also do drive_deauth()
.
library(googledrive) drive_deauth()
Call drive_examples_local()
to get the full filepaths.
basename()
(and fs::path_file()
) are handy functions for getting just the filename.
(x <- drive_examples_local()) basename(x)
You can filter the files by providing a regular expression.
drive_examples_local("csv") %>% basename()
If you want exactly one file, use the singular drive_example_local()
and provide the file's name (or any sufficiently specific regular expression):
drive_examples_local("chicken.jpg") %>% basename() drive_examples_local("imdb") %>% basename()
Here's how you might use one of these examples to start demonstrating something with googledrive:
new_google_sheet <- drive_examples_local("chicken.csv") %>% drive_upload(type = "spreadsheet") # ... example or reprex continues ...
Call drive_examples_remote()
to get a dribble
of the remote example files.
Here I also reveal their MIME type.
drive_examples_remote() %>% drive_reveal("mime_type")
You'll notice there are two files that aren't among the local example files, but that are derived from them:
chicken_doc
: a Google Document made from chicken.txt
chicken_sheet
: a Google Sheet made from chicken.csv
Here's a clickable table of the remote example files:
dat <- drive_examples_remote() %>% drive_reveal("webViewLink") dat2 <- tibble::tibble( `name (these are links)` = glue::glue_data(dat, "[{name}]({web_view_link})"), id = unclass(dat$id) )
knitr::kable(dat2)
Accessing the remote example files works just like the local files. Provide a regular expression to specify the name of target file(s). Use the singular form to target exactly one file.
drive_examples_remote("chicken") drive_example_remote("logo")
Here's how you might use one of these examples to start demonstrating something with googledrive:
new_google_doc <- drive_examples_remote("chicken_doc") %>% drive_cp(name = "I have a chicken problem") # ... example or reprex continues ...
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.