Skip to content

Instantly share code, notes, and snippets.

@aaronwolen
Created December 27, 2018 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronwolen/58534585e94830dacba059a69fdf4d0b to your computer and use it in GitHub Desktop.
Save aaronwolen/58534585e94830dacba059a69fdf4d0b to your computer and use it in GitHub Desktop.
osfr demo
# devtools::install_github("aaronwolen/osfr")
library(osfr2)
library(stringr)
# retrieve a user
user <- osf_retrieve_user("alh38")
user
# this is an osf_tbl_user
class(user)
# view any osf_tbl directly on osf.io with osf_open()
osf_open(user)
# list user's projects/components
projects <- osf_ls_nodes(user, n_max = 50)
projects
# this is an osf_tbl_node for representing projects/components
class(projects)
# list files within a particular project
files <- osf_ls_files(projects[9, ])
files
# this is an osf_tbl_file for representing files/directories
class(files)
# open an individual file on osf.io
osf_open(files[3,])
# osf_tbls are pipe-friendly (NOTE: still need to add dplyr compatibility)
# e.g. open the keywords.xlsx file from the cancer reproducibility project
projects %>%
subset(str_detect(name, "Cancer Biology")) %>%
osf_ls_files() %>%
subset(str_detect(name, "keywords.xlsx")) %>%
osf_open()
# upload a file to a new subcomponent of a new project and view it
logo <- system.file("help/figures/logo.png", package = "purrr")
osf_logo <- osf_project_create("Media") %>%
osf_component_create("Logos", description = "R Package Logos") %>%
osf_upload(logo)
# we can open a newly uploaded file on osf.io even though GUID's aren't
# assigned until a file has been loaded in the browser
osf_open(osf_logo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment