|
| 1 | +library(desc) |
| 2 | +library(tidyverse) |
| 3 | +library(zen4R) |
| 4 | +library(git2r) |
| 5 | + |
| 6 | +authors_df <- desc_get_field("Authors@R") %>% |
| 7 | + str_remove_all('("|\\(|\\)|,)') %>% |
| 8 | + str_split("person") %>% |
| 9 | + map(str_extract_all, pattern = "(given|family|affiliation|ORCID) = .*") %>% |
| 10 | + flatten() %>% |
| 11 | + map(as_tibble) %>% |
| 12 | + map_dfr(separate, col = "value", into = c("name", "value"), sep = " = ", .id = "id") %>% |
| 13 | + pivot_wider() %>% |
| 14 | + transmute(name = glue::glue("{family}, {given}"), |
| 15 | + affiliation = affiliation, |
| 16 | + orcid = ORCID) |
| 17 | + |
| 18 | +lesson_title <- desc_get_field("Title") %>% |
| 19 | + str_remove_all("\"") %>% |
| 20 | + str_remove_all("\\n") %>% |
| 21 | + str_replace_all(" +", " ") %>% |
| 22 | + str_replace(":", " -") |
| 23 | + |
| 24 | +description_content <- desc_get_field("Description") %>% |
| 25 | + str_remove_all("\\n") %>% |
| 26 | + str_replace_all(" +", " ") |
| 27 | + |
| 28 | +repo <- repository() |
| 29 | +repo_version <- str_c("v", as.character(desc::desc_get_version())) |
| 30 | +version_tag <- tag(repo, name = repo_version, message = "Teaching material used for the Sept 8-9, 2020 course.") |
| 31 | +tag_files <- ls_tree(tree(lookup_commit(version_tag))) |
| 32 | +zip("r-cubed-intermediate.zip", tag_files) |
| 33 | + |
| 34 | +new_record <- ZenodoRecord$new() |
| 35 | +pwalk(authors_df, new_record$addCreator) |
| 36 | +new_record$setUploadType("lesson") |
| 37 | +new_record$setTitle(str_c("r-cubed: ", lesson_title)) |
| 38 | +new_record$setDescription(description_content) |
| 39 | +new_record$setLicense("cc-by") |
| 40 | +new_record$addRelatedIdentifier("isCompiledBy", "https://gitlab.com/rostools/r-cubed-intermediate") |
| 41 | +new_record$addRelatedIdentifier("isIdenticalTo", "https://gitlab.com/rostools/r-cubed-intermediate/-/tags/v0.1.0") |
| 42 | + |
| 43 | +zenodo <- ZenodoManager$new( |
| 44 | + url = "https://sandbox.zenodo.org/api", |
| 45 | + logger = "INFO" |
| 46 | +) |
| 47 | + |
| 48 | +deposited_record <- zenodo$depositRecord(new_record) |
| 49 | +zenodo$uploadFile("r-cubed-intermediate.zip", deposited_record$id) |
0 commit comments