Skip to content

Commit a0e94d2

Browse files
added citation_cff fn
1 parent d8099d0 commit a0e94d2

11 files changed

Lines changed: 180 additions & 27 deletions

File tree

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@
5454
^doc$
5555
^Meta$
5656
^data-raw/FUNCTIONS\.R$
57+
^data-raw/WIP\.R$

CITATION.cff

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cff-version: 1.2.0
2+
message: "Matthew P Hamilton (2021). ready4: Implement Open Science Computational Models of Mental Health
3+
Systems. Version 0.0.0.9089. Zenodo. https://doi.org/10.5281/zenodo.5606250"
4+
authors:
5+
- family-names: "Matthew P"
6+
given-names: "Hamilton"
7+
title: "ready4: Implement Open Science Computational Models of Mental Health
8+
Systems"
9+
version: 0.0.0.9089
10+
doi: 10.5281/zenodo.5606250
11+
date-released: 2022-02-15
12+
url: "https://ready4-dev.github.io/ready4/"

DESCRIPTION

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Collate:
2626
'C4_Ready4Module.R'
2727
'C4_Ready4Private.R'
2828
'C4_Ready4Public.R'
29-
'add.R'
3029
'fn_add.R'
3130
'fn_get.R'
3231
'fn_make.R'
@@ -36,11 +35,9 @@ Collate:
3635
'fn_transform.R'
3736
'fn_update.R'
3837
'fn_write.R'
39-
'get.R'
4038
'grp_generics.R'
4139
'imp_fns.R'
4240
'imp_mthds.R'
43-
'make.R'
4441
'mthd_authorSlot.R'
4542
'mthd_characterizeSlot.R'
4643
'mthd_depictSlot.R'
@@ -57,13 +54,7 @@ Collate:
5754
'mthd_renewSlot.R'
5855
'mthd_shareSlot.R'
5956
'pkg_ready4.R'
60-
'print.R'
6157
'ready4-package.R'
62-
'remove.R'
63-
'rowbind.R'
64-
'transform.R'
65-
'update.R'
66-
'write.R'
6758
Imports:
6859
assertthat,
6960
bib2df,

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export(transform_cls_type_ls)
8585
export(update_pt_fn_args_ls)
8686
export(update_tb_r3)
8787
export(write_all_tbs_in_tbs_r4_to_csvs)
88+
export(write_citation_cff)
8889
export(write_dv_fl_to_loc)
8990
export(write_env_objs_to_dv)
9091
export(write_fls_from_dv)
@@ -99,6 +100,7 @@ export(write_to_delete_fls)
99100
export(write_to_dv_from_tbl)
100101
export(write_to_dv_with_wait)
101102
export(write_to_publish_dv_ds)
103+
export(write_words)
102104
export(write_ws)
103105
exportClasses(Ready4Module)
104106
exportClasses(Ready4Private)
@@ -198,6 +200,8 @@ importFrom(stringr,str_locate)
198200
importFrom(stringr,str_match)
199201
importFrom(stringr,str_remove)
200202
importFrom(stringr,str_remove_all)
203+
importFrom(stringr,str_replace)
204+
importFrom(stringr,str_replace_all)
201205
importFrom(stringr,str_sub)
202206
importFrom(testit,assert)
203207
importFrom(tibble,as_tibble)

R/fn_write.R

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@ write_all_tbs_in_tbs_r4_to_csvs <- function (tbs_r4, r4_name_1L_chr, lup_dir_1L_
1717
r4_name_1L_chr = r4_name_1L_chr, lup_dir_1L_chr = lup_dir_1L_chr,
1818
pfx_1L_chr = pfx_1L_chr))
1919
}
20+
#' Write citation cff
21+
#' @description write_citation_cff() is a Write function that writes a file to a specified local directory. Specifically, this function implements an algorithm to write citation cff. The function is called for its side effects and does not return a value. WARNING: This function writes R scripts to your local environment. Make sure to only use if you want this behaviour
22+
#' @param pkg_desc_ls Package description (a list)
23+
#' @param citation_chr Citation (a character vector)
24+
#' @param publisher_1L_chr Publisher (a character vector of length one), Default: 'Zenodo'
25+
#' @return NULL
26+
#' @rdname write_citation_cff
27+
#' @export
28+
#' @importFrom stringr str_sub str_replace_all str_remove str_replace
29+
#' @importFrom purrr map2_chr
30+
#' @keywords internal
31+
write_citation_cff <- function (pkg_desc_ls, citation_chr, publisher_1L_chr = "Zenodo")
32+
{
33+
meta <- pkg_desc_ls
34+
authors_ls <- parse(text = paste0("list(", citation_chr[startsWith(citation_chr,
35+
" author = ")] %>% stringr::str_sub(start = 16, end = -3) %>%
36+
stringr::str_replace_all("person", "c"), ")")) %>% eval()
37+
citation_cff_chr <- c("cff-version: 1.2.0", paste0("message: \"",
38+
parse(text = citation_chr[which(citation_chr %>% startsWith(" textVersion = ")):(length(citation_chr) -
39+
1)] %>% stringr::str_remove(" textVersion = ") %>%
40+
paste0(collapse = "\n")) %>% eval() %>% stringr::str_replace(paste0(meta$Version,
41+
"."), paste0(meta$Version, ". ", publisher_1L_chr,
42+
".")), "\""), "authors:", purrr::map2_chr(authors_ls,
43+
1:length(authors_ls), ~paste0(" - family-names: \"",
44+
.x[1], "\"\n", " given-names: \"", .x[2], ifelse(.y ==
45+
length(authors_ls), "\"", "\"\n"))), paste0("title: \"",
46+
paste0(meta$Package, ": ", meta$Title), "\""), paste0("version: ",
47+
meta$Version), paste0("doi: ", citation_chr[startsWith(citation_chr,
48+
" doi = ")] %>% stringr::str_sub(start = 15, end = -3)),
49+
paste0("date-released: ", Sys.Date()), paste0("url: \"",
50+
citation_chr[startsWith(citation_chr, " url = ")] %>%
51+
stringr::str_sub(start = 15, end = -3), "\""))
52+
write_new_files("CITATION.cff", fl_nm_1L_chr = "CITATION",
53+
text_ls = list(citation_cff_chr))
54+
}
2055
#' Write dataverse file to local
2156
#' @description write_dv_fl_to_loc() is a Write function that writes a file to a specified local directory. Specifically, this function implements an algorithm to write dataverse file to local. The function is called for its side effects and does not return a value. WARNING: This function writes R scripts to your local environment. Make sure to only use if you want this behaviour
2257
#' @param ds_ui_1L_chr Dataset user interface (a character vector of length one)
@@ -644,6 +679,28 @@ write_to_publish_dv_ds <- function (dv_ds_1L_chr)
644679
dataverse::publish_dataset(dv_ds_1L_chr, minor = F)
645680
}
646681
}
682+
#' Write words
683+
#' @description write_words() is a Write function that writes a file to a specified local directory. Specifically, this function implements an algorithm to write words. The function is called for its side effects and does not return a value. WARNING: This function writes R scripts to your local environment. Make sure to only use if you want this behaviour
684+
#' @param new_words_chr New words (a character vector)
685+
#' @param gh_repo_1L_chr Github repository (a character vector of length one), Default: 'ready4-dev/ready4'
686+
#' @param gh_tag_1L_chr Github tag (a character vector of length one), Default: 'Documentation_0.0'
687+
#' @return NULL
688+
#' @rdname write_words
689+
#' @export
690+
#' @importFrom piggyback pb_download_url
691+
#' @keywords internal
692+
write_words <- function (new_words_chr, gh_repo_1L_chr = "ready4-dev/ready4",
693+
gh_tag_1L_chr = "Documentation_0.0")
694+
{
695+
dmt_urls_chr <- piggyback::pb_download_url(repo = gh_repo_1L_chr,
696+
tag = gh_tag_1L_chr, .token = "")
697+
b <- readRDS(url(dmt_urls_chr[dmt_urls_chr %>% endsWith("treat_as_words_chr.RDS")]))
698+
b <- c(b, new_words_chr) %>% sort()
699+
write_env_objs_to_dv(env_objects_ls = list(treat_as_words_chr = b),
700+
descriptions_chr = NULL, ds_url_1L_chr = character(0),
701+
piggyback_desc_1L_chr = "Supplementary Files", piggyback_tag_1L_chr = gh_tag_1L_chr,
702+
piggyback_to_1L_chr = gh_repo_1L_chr, prerelease_1L_lgl = T)
703+
}
647704
#' Write workspace
648705
#' @description write_ws() is a Write function that writes a file to a specified local directory. Specifically, this function implements an algorithm to write workspace. The function is called for its side effects and does not return a value. WARNING: This function writes R scripts to your local environment. Make sure to only use if you want this behaviour
649706
#' @param path_1L_chr Path (a character vector of length one)

data-raw/DATASET.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ x <- ready4fun::make_pkg_desc_ls(pkg_title_1L_chr = "Implement Open Science Comp
88
authors_prsn = c(utils::person(
99
given = "Matthew",family = "Hamilton", email =
1010
"matthew.hamilton@orygen.org.au",role = c("aut",
11-
"cre"),comment = c(ORCID = "0000-0001-7407-9194")
11+
"cre"),
12+
comment = c(ORCID = "0000-0001-7407-9194")
1213
),
1314
utils::person("Orygen", role = c("cph", "fnd")),
1415
utils::person("VicHealth",role = c("fnd")),
@@ -44,9 +45,9 @@ x <- ready4fun::make_pkg_desc_ls(pkg_title_1L_chr = "Implement Open Science Comp
4445
## Do you confirm ('Y') that you want to delete these files: [Y|N]
4546
## After doing so, all other such prompts should be answered in the affirmative.
4647
x <- write_self_srvc_pkg(x)
48+
# ADD DOI OVERRIDE FOR RELEASES
4749
#
4850
# write_extensions() # Required only if extensions have changed since last build
4951
# write_badges() # Only run if the ready4fun badges table has been updated.
5052
# Very occasional calls to write_housestyle_fls (four a year tops)
5153
devtools::build_vignettes()
52-
#

data-raw/FUNCTIONS.R

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ write_self_srvc_pkg <- function(x){
408408
}
409409
write_to_delete_dirs("safety")
410410
write_prototypes()
411+
write_citation_cff(packageDescription("ready4"),
412+
citation_chr = readLines("inst/CITATION"))
411413
return(x)
412414
}
413415
write_prototypes <- function(gh_repo_1L_chr = "ready4-dev/ready4",
@@ -458,22 +460,7 @@ write_extensions <- function(gh_repo_1L_chr = "ready4-dev/ready4",
458460
piggyback_to_1L_chr = gh_repo_1L_chr,
459461
prerelease_1L_lgl = T)
460462
}
461-
write_words <- function(new_words_chr,
462-
gh_repo_1L_chr = "ready4-dev/ready4",
463-
gh_tag_1L_chr = "Documentation_0.0"){
464-
dmt_urls_chr <- piggyback::pb_download_url(repo = gh_repo_1L_chr,
465-
tag = gh_tag_1L_chr,
466-
.token = "")
467-
b <- readRDS(url(dmt_urls_chr[dmt_urls_chr %>% endsWith("treat_as_words_chr.RDS")]))
468-
b <- c(b,new_words_chr) %>% sort()
469-
write_env_objs_to_dv(env_objects_ls = list(treat_as_words_chr = b),
470-
descriptions_chr = NULL,
471-
ds_url_1L_chr = character(0),
472-
piggyback_desc_1L_chr = "Supplementary Files",
473-
piggyback_tag_1L_chr = gh_tag_1L_chr,
474-
piggyback_to_1L_chr = gh_repo_1L_chr,
475-
prerelease_1L_lgl = T)
476-
}
463+
477464

478465
write_housestyle_fls <- function(){ # Use sparingly [Max 4 times a year]
479466
X <- ready4use::Ready4useRepos(dv_nm_1L_chr = "ready4fw",

data-raw/WIP.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
meta <- packageDescription("ready4")
2+
citation_chr <- readLines("inst/CITATION")
3+
publisher_1L_chr <- "Zenodo"
4+
5+
write_citation_cff(packageDescription("ready4"),
6+
citation_chr = readLines("inst/CITATION"))

data-raw/fns/write.R

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,42 @@ write_all_tbs_in_tbs_r4_to_csvs <- function(tbs_r4,
99
lup_dir_1L_chr = lup_dir_1L_chr,
1010
pfx_1L_chr = pfx_1L_chr))
1111
}
12+
write_citation_cff <- function(pkg_desc_ls,
13+
citation_chr,
14+
publisher_1L_chr = "Zenodo"){
15+
meta <- pkg_desc_ls
16+
authors_ls <- parse(text=paste0("list(",
17+
citation_chr[startsWith(citation_chr," author = ")] %>%
18+
stringr::str_sub(start=16, end=-3) %>%
19+
stringr::str_replace_all("person","c"),
20+
")")) %>%
21+
eval()
22+
citation_cff_chr <- c("cff-version: 1.2.0",
23+
paste0("message: \"",
24+
parse(text = citation_chr[which(citation_chr %>%
25+
startsWith(" textVersion = ")):(length(citation_chr)-1)] %>%
26+
stringr::str_remove(" textVersion = ") %>%
27+
paste0(collapse = "\n")) %>%
28+
eval() %>%
29+
stringr::str_replace(paste0(meta$Version,"."),
30+
paste0(meta$Version,". ",publisher_1L_chr,".")),
31+
"\""),
32+
"authors:",
33+
purrr::map2_chr(authors_ls,
34+
1:length(authors_ls),
35+
~ paste0(" - family-names: \"",.x[1],"\"\n",
36+
" given-names: \"",.x[2],ifelse(.y==length(authors_ls),"\"","\"\n")#" orcid: ",
37+
)),
38+
paste0("title: \"",paste0(meta$Package,": ",meta$Title),"\""),
39+
paste0("version: ",meta$Version),
40+
paste0("doi: ",citation_chr[startsWith(citation_chr," doi = ")] %>% stringr::str_sub(start=15,end=-3)),
41+
paste0("date-released: ",Sys.Date()),
42+
paste0("url: \"",citation_chr[startsWith(citation_chr," url = ")] %>% stringr::str_sub(start=15,end=-3),"\""))
43+
write_new_files("CITATION.cff",
44+
fl_nm_1L_chr = "CITATION",
45+
text_ls = list(citation_cff_chr))
46+
47+
}
1248
write_dv_fl_to_loc <- function(ds_ui_1L_chr,
1349
fl_nm_1L_chr = NA_character_,
1450
fl_id_1L_int = NA_integer_,
@@ -572,6 +608,22 @@ write_to_publish_dv_ds <- function(dv_ds_1L_chr){
572608
minor = F)
573609
}
574610
}
611+
write_words <- function(new_words_chr,
612+
gh_repo_1L_chr = "ready4-dev/ready4",
613+
gh_tag_1L_chr = "Documentation_0.0"){
614+
dmt_urls_chr <- piggyback::pb_download_url(repo = gh_repo_1L_chr,
615+
tag = gh_tag_1L_chr,
616+
.token = "")
617+
b <- readRDS(url(dmt_urls_chr[dmt_urls_chr %>% endsWith("treat_as_words_chr.RDS")]))
618+
b <- c(b,new_words_chr) %>% sort()
619+
write_env_objs_to_dv(env_objects_ls = list(treat_as_words_chr = b),
620+
descriptions_chr = NULL,
621+
ds_url_1L_chr = character(0),
622+
piggyback_desc_1L_chr = "Supplementary Files",
623+
piggyback_tag_1L_chr = gh_tag_1L_chr,
624+
piggyback_to_1L_chr = gh_repo_1L_chr,
625+
prerelease_1L_lgl = T)
626+
}
575627
write_ws <- function(path_1L_chr){
576628
top_level_chr <- paste0(path_1L_chr,
577629
"/ready4/",

man/write_citation_cff.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)