Created
June 22, 2021 16:18
-
-
Save aaronwolen/8f84828c67d610dd1a5b1160c5e8a403 to your computer and use it in GitHub Desktop.
Use osfr to download individual OSF Wikis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(osfr) | |
| library(purrr) | |
| library(tibble) | |
| # functions --------------------------------------------------------------- | |
| # id: project GUID | |
| .osf_list_wikis <- function(id) { | |
| api_path <- sprintf("nodes/%s/wikis", id) | |
| res <- osfr:::.osf_request("get", path) | |
| osfr:::process_response(res) | |
| } | |
| # id: wiki GUID | |
| # path: local path where wiki will be downloaded | |
| .osf_download_wikis <- function(id, path) { | |
| api_path <- sprintf("wikis/%s/content/", id) | |
| res <- osfr:::.osf_request("get", api_path, disk = path) | |
| if (res$status_code == 200) return(invisible(TRUE)) | |
| res$raise_for_status() | |
| } | |
| # demo -------------------------------------------------------------------- | |
| # project guid | |
| pid <- "ezum7" | |
| # list all wikis associated with the project | |
| wikis <- .osf_node_wikis(pid) | |
| # convert to a data frme | |
| tbl_wikis <- tibble::tibble( | |
| id = map_chr(wikis$data, purrr::chuck, "id"), | |
| name = map_chr(wikis$data, purrr::chuck, "attributes", "name"), | |
| date_modified = as.POSIXct( | |
| map_dbl(wikis$data, purrr::chuck, "attributes", "date_modified"), | |
| origin = as.Date("1970-01-01") | |
| ) | |
| ) | |
| # download a particular wiki to local file | |
| i <- 1 | |
| .osf_download_wikis(tbl_wikis$id[i], paste0(tbl_wikis$name[i], ".md")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment