Skip to content

Commit ec38b58

Browse files
added TTUSynopsis class
1 parent df979e0 commit ec38b58

15 files changed

Lines changed: 405 additions & 60 deletions

CITATION.cff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cff-version: 1.2.0
2-
message: "Caroline Gao and Matthew Hamilton (2022). TTU: Implement Transfer to Utility Mapping Algorithms. Version 0.0.0.9335. Zenodo. https://doi.org/10.5281/zenodo.5646593"
2+
message: "Caroline Gao and Matthew Hamilton (2022). TTU: Implement Transfer to Utility Mapping Algorithms. Version 0.0.0.9337. Zenodo. https://doi.org/10.5281/zenodo.5646593"
33
authors:
44
- family-names: "Gao"
55
given-names: "Caroline"
66
- family-names: "Hamilton"
77
given-names: "Matthew"
88
title: "TTU: Implement Transfer to Utility Mapping Algorithms"
9-
version: 0.0.0.9335
9+
version: 0.0.0.9337
1010
doi: 10.5281/zenodo.5646593
11-
date-released: 2022-02-18
11+
date-released: 2022-02-22
1212
url: "https://ready4-dev.github.io/TTU/"

NAMESPACE

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@
22

33
export("%>%")
44
export(TTUReports)
5+
export(TTUSynopsis)
56
export(deprecated)
7+
export(get_pkg_citation)
68
export(make_report_fl_nms_ls)
79
exportClasses(TTUReports)
10+
exportClasses(TTUSynopsis)
811
exportMethods(author)
912
import(methods)
1013
import(ready4)
14+
import(specific)
15+
importFrom(dplyr,mutate)
16+
importFrom(ggplot2,ggsave)
1117
importFrom(lifecycle,deprecated)
1218
importFrom(magrittr,"%>%")
19+
importFrom(purrr,discard)
20+
importFrom(purrr,flatten_chr)
21+
importFrom(purrr,map)
22+
importFrom(purrr,map_chr)
23+
importFrom(purrr,pluck)
24+
importFrom(purrr,reduce)
1325
importFrom(ready4,author)
1426
importFrom(ready4show,make_rmd_fl_nms_ls)
27+
importFrom(stringr,str_locate)
28+
importFrom(stringr,str_replace_all)
29+
importFrom(stringr,str_sub)
30+
importFrom(utils,packageDescription)

R/C4_TTUReports.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#' TTUReports
2-
#'
2+
#'
33
#' Metadata to produce utility mapping study reports.
4-
#'
5-
#' @slot a_SpecificSynopsis (an instance of the SpecificSynopsis class)
4+
#'
5+
#' @include C4_TTUSynopsis.R
6+
#' @slot a_TTUSynopsis (an instance of the TTUSynopsis class)
67
#' @slot catalogue_tmpl_chr Catalogue template (a character vector)
78
#' @slot catalogue_fl_nms_ls Catalogue file names (a list)
89
#' @slot manuscript_tmpl_chr Manuscript template (a character vector)
@@ -15,8 +16,8 @@
1516
#' @exportClass TTUReports
1617
TTUReports <- methods::setClass("TTUReports",
1718
contains = "Ready4Module",
18-
slots = c(a_SpecificSynopsis = "SpecificSynopsis",catalogue_tmpl_chr = "character",catalogue_fl_nms_ls = "list",manuscript_tmpl_chr = "character",manuscript_fl_nms_ls = "list",dissemination_1L_chr = "character"),
19-
prototype = list(a_SpecificSynopsis = specific::SpecificSynopsis(),catalogue_tmpl_chr = c("https://github.com/ready4-dev/ttu_mdl_ctlg","0.0.9.5"),catalogue_fl_nms_ls = ready4show::make_rmd_fl_nms_ls("Lngl_Mdls_HTML",
19+
slots = c(a_TTUSynopsis = "TTUSynopsis",catalogue_tmpl_chr = "character",catalogue_fl_nms_ls = "list",manuscript_tmpl_chr = "character",manuscript_fl_nms_ls = "list",dissemination_1L_chr = "character"),
20+
prototype = list(a_TTUSynopsis = TTUSynopsis(),catalogue_tmpl_chr = c("https://github.com/ready4-dev/ttu_mdl_ctlg","0.0.9.5"),catalogue_fl_nms_ls = ready4show::make_rmd_fl_nms_ls("Lngl_Mdls_HTML",
2021
pdf_fl_nm_1L_chr = "Lngl_Mdls_PDF",
2122
word_fl_nm_1L_chr = "Lngl_Mdls_Word"),manuscript_tmpl_chr = c("https://github.com/ready4-dev/ttu_lng_ss","0.6"),manuscript_fl_nms_ls = ready4show::make_rmd_fl_nms_ls(pdf_fl_nm_1L_chr = "Main_PDF",
2223
word_fl_nm_1L_chr = "Main_Word")))

R/C4_TTUSynopsis.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#' TTUSynopsis
2+
#'
3+
#' Input, Output and Authorship Data For Generating Utility Mapping Study Reports.
4+
#'
5+
#' @slot a_Ready4showPaths (an instance of the Ready4showPaths class)
6+
#' @slot b_SpecificResults (an instance of the SpecificResults class)
7+
#' @slot c_SpecificParameters (an instance of the SpecificParameters class)
8+
#' @slot d_YouthvarsProfile (an instance of the YouthvarsProfile class)
9+
#' @slot e_Ready4useRepos (an instance of the Ready4useRepos class)
10+
#' @slot abstract_args_ls Abstract arguments (a list)
11+
#' @slot authors_r3 Authors (a ready4 S3)
12+
#' @slot background_1L_chr Background (a character vector of length one)
13+
#' @slot coi_1L_chr Conflict of interest (a character vector of length one)
14+
#' @slot conclusion_1L_chr Conclusion (a character vector of length one)
15+
#' @slot correspondences_r3 Correspondences (a ready4 S3)
16+
#' @slot digits_int Digits (an integer vector)
17+
#' @slot ethics_1L_chr Ethics (a character vector of length one)
18+
#' @slot fl_nm_1L_chr File name (a character vector of length one)
19+
#' @slot figures_in_body_lgl Figures in body (a logical vector)
20+
#' @slot funding_1L_chr Funding (a character vector of length one)
21+
#' @slot institutes_r3 Institutes (a ready4 S3)
22+
#' @slot interval_chr Interval (a character vector)
23+
#' @slot keywords_chr Keywords (a character vector)
24+
#' @slot outp_formats_chr Output formats (a character vector)
25+
#' @slot rmd_fl_nms_ls R Markdown file names (a list)
26+
#' @slot sample_desc_1L_chr Sample description (a character vector of length one)
27+
#' @slot tables_in_body_lgl Tables in body (a logical vector)
28+
#' @slot title_1L_chr Title (a character vector of length one)
29+
#' @slot dissemination_1L_chr Dissemination (a character vector of length one)
30+
#' @import specific
31+
#' @name TTUSynopsis-class
32+
#' @rdname TTUSynopsis-class
33+
#' @export TTUSynopsis
34+
#' @exportClass TTUSynopsis
35+
TTUSynopsis <- methods::setClass("TTUSynopsis",
36+
contains = "SpecificSynopsis",
37+
slots = c(a_Ready4showPaths = "Ready4showPaths",b_SpecificResults = "SpecificResults",c_SpecificParameters = "SpecificParameters",d_YouthvarsProfile = "YouthvarsProfile",e_Ready4useRepos = "Ready4useRepos",abstract_args_ls = "list",authors_r3 = "ready4show_authors",background_1L_chr = "character",coi_1L_chr = "character",conclusion_1L_chr = "character",correspondences_r3 = "ready4show_correspondences",digits_int = "integer",ethics_1L_chr = "character",fl_nm_1L_chr = "character",figures_in_body_lgl = "logical",funding_1L_chr = "character",institutes_r3 = "ready4show_institutes",interval_chr = "character",keywords_chr = "character",outp_formats_chr = "character",rmd_fl_nms_ls = "list",sample_desc_1L_chr = "character",tables_in_body_lgl = "logical",title_1L_chr = "character",dissemination_1L_chr = "character"),
38+
prototype = list(a_Ready4showPaths = ready4show::Ready4showPaths(),b_SpecificResults = specific::SpecificResults(),c_SpecificParameters = specific::SpecificParameters(),d_YouthvarsProfile = youthvars::YouthvarsProfile(),e_Ready4useRepos = ready4use::Ready4useRepos()))
39+
40+
41+
methods::setValidity(methods::className("TTUSynopsis"),
42+
function(object){
43+
msg <- NULL
44+
if (is.null(msg)) TRUE else msg
45+
})

R/fn_get.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#' Get package citation
2+
#' @description get_pkg_citation() is a Get function that retrieves a pre-existing data object from memory, local file system or online repository. Specifically, this function implements an algorithm to get package citation. Function argument pkg_nm_1L_chr specifies the where to look for the required object. The function returns Citation (a character vector of length one).
3+
#' @param pkg_nm_1L_chr Package name (a character vector of length one)
4+
#' @return Citation (a character vector of length one)
5+
#' @rdname get_pkg_citation
6+
#' @export
7+
#' @keywords internal
8+
get_pkg_citation <- function (pkg_nm_1L_chr)
9+
{
10+
citation_chr <- suppressWarnings(citation(pkg_nm_1L_chr)) %>%
11+
capture.output()
12+
start_idx_1L_int <- 4
13+
end_idx_1L_int <- which(citation_chr == "")[which(which(citation_chr ==
14+
"") > start_idx_1L_int)[1]] - 1
15+
citation_1L_chr <- citation_chr[start_idx_1L_int:end_idx_1L_int] %>%
16+
paste0(collapse = "")
17+
return(citation_1L_chr)
18+
}

R/mthd_author.R

Lines changed: 83 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,97 @@
33
#' @name author-TTUReports
44
#' @description author method applied to TTUReports
55
#' @param x An object of class TTUReports
6+
#' @param depnt_var_desc_1L_chr Dependent variable description (a character vector of length one), Default: 'NA'
67
#' @param download_tmpl_1L_lgl Download template (a logical vector of length one), Default: T
7-
#' @param what_1L_chr What (a character vector of length one), Default: 'Catalogue'
8+
#' @param fl_type_1L_chr File type (a character vector of length one), Default: '.eps'
9+
#' @param timepoint_new_nms_chr Timepoint new names (a character vector), Default: 'NA'
10+
#' @param type_1L_chr Type (a character vector of length one), Default: 'Report'
11+
#' @param what_1L_chr What (a character vector of length one), Default: 'NA'
812
#' @return NULL
913
#' @rdname author-methods
1014
#' @aliases author,TTUReports-method
1115
#' @export
16+
#' @importFrom purrr map flatten_chr discard reduce map_chr pluck
17+
#' @importFrom utils packageDescription
18+
#' @importFrom stringr str_replace_all str_locate str_sub
19+
#' @importFrom dplyr mutate
20+
#' @importFrom ggplot2 ggsave
1221
#' @importFrom ready4 author
13-
methods::setMethod("author", "TTUReports", function (x, download_tmpl_1L_lgl = T, what_1L_chr = "Catalogue")
22+
methods::setMethod("author", "TTUReports", function (x, depnt_var_desc_1L_chr = NA_character_, download_tmpl_1L_lgl = T,
23+
fl_type_1L_chr = ".eps", timepoint_new_nms_chr = NA_character_,
24+
type_1L_chr = "Report", what_1L_chr = NA_character_)
1425
{
15-
if (download_tmpl_1L_lgl) {
16-
authorData(x@a_SpecificSynopsis, tmpl_url_1L_chr = ifelse(what_1L_chr ==
17-
"Catalogue", x@catalogue_tmpl_chr[1], x@manuscript_tmpl_chr[1]),
18-
tmpl_version_1_L_chr = ifelse(what_1L_chr == "Catalogue",
19-
x@catalogue_tmpl_chr[2], x@manuscript_tmpl_chr[2]),
20-
what_1L_chr = what_1L_chr)
21-
}
22-
if (what_1L_chr == "Catalogue") {
23-
x@a_SpecificSynopsis@rmd_fl_nms_ls <- x@catalogue_fl_nms_ls
24-
}
25-
else {
26-
x@a_SpecificSynopsis@rmd_fl_nms_ls <- x@manuscript_fl_nms_ls
27-
}
28-
if (what_1L_chr == "Catalogue") {
29-
author(x@a_SpecificSynopsis, type_1L_chr = "Report",
30-
what_1L_chr = what_1L_chr)
26+
if (type_1L_chr == "Report") {
27+
if (download_tmpl_1L_lgl) {
28+
authorData(x@a_TTUSynopsis, tmpl_url_1L_chr = ifelse(what_1L_chr ==
29+
"Catalogue", x@catalogue_tmpl_chr[1], x@manuscript_tmpl_chr[1]),
30+
tmpl_version_1_L_chr = ifelse(what_1L_chr ==
31+
"Catalogue", x@catalogue_tmpl_chr[2], x@manuscript_tmpl_chr[2]),
32+
what_1L_chr = what_1L_chr)
33+
}
34+
if (what_1L_chr == "Catalogue") {
35+
x@a_TTUSynopsis@rmd_fl_nms_ls <- x@catalogue_fl_nms_ls
36+
}
37+
else {
38+
x@a_TTUSynopsis@rmd_fl_nms_ls <- x@manuscript_fl_nms_ls
39+
}
40+
if (what_1L_chr == "Catalogue") {
41+
author(x@a_TTUSynopsis, type_1L_chr = "Report", what_1L_chr = what_1L_chr)
42+
}
43+
else {
44+
authorReport(x@a_TTUSynopsis, what_1L_chr = what_1L_chr)
45+
}
3146
}
3247
else {
33-
authorReport(x@a_SpecificSynopsis, what_1L_chr = what_1L_chr)
48+
dir_1L_chr <- paste0(x@a_TTUSynopsis@a_Ready4showPaths@outp_data_dir_1L_chr,
49+
"/", x@a_TTUSynopsis@a_Ready4showPaths@mkdn_data_dir_1L_chr,
50+
"/", what_1L_chr)
51+
if (type_1L_chr == "Dependencies") {
52+
df <- data.frame(Package = c("youthvars", "scorz",
53+
"specific", "TTU", ) %>% purrr::map(~{
54+
utils::packageDescription(.x) %>% c("Depends",
55+
"Imports")[] %>% purrr::map(~{
56+
if (is.null(.x)) {
57+
character(0)
58+
}
59+
else {
60+
.x %>% strsplit(",\\n") %>% purrr::flatten_chr() %>%
61+
purrr::map(~strsplit(.x, ", ") %>% purrr::flatten_chr()) %>%
62+
purrr::flatten_chr() %>% sort() %>% purrr::discard(~startsWith(.x,
63+
"R "))
64+
}
65+
}) %>% purrr::flatten_chr() %>% unique() %>%
66+
sort()
67+
}) %>% purrr::reduce(~c(.x, .y)) %>% purrr::map_chr(~{
68+
updated_1L_chr <- stringr::str_replace_all(.x,
69+
"\\n", " ")
70+
problem_idx_1L_chr <- stringr::str_locate(updated_1L_chr,
71+
" ")[1, 1] %>% unname()
72+
if (!is.na(problem_idx_1L_chr))
73+
updated_1L_chr <- updated_1L_chr %>% stringr::str_sub(end = problem_idx_1L_chr -
74+
1)
75+
updated_1L_chr %>% trimws(which = "left")
76+
}) %>% unique() %>% sort())
77+
df <- df %>% dplyr::mutate(Version = Package %>%
78+
purrr::map_chr(~utils::packageDescription(.x) %>%
79+
purrr::pluck("Version")), Citation = Package %>%
80+
purrr::map_chr(~get_pkg_citation(.x)))
81+
saveRDS(df, paste0(dir_1L_chr, "/packages.RDS"))
82+
}
83+
if (type_1L_chr == "Plots") {
84+
composite_1_plt <- depictSlot(x, "a_TTUSynopsis",
85+
depnt_var_desc_1L_chr = depnt_var_desc_1L_chr,
86+
timepoint_old_nms_chr = procureSlot(x, "a_TTUSynopsis@d_YouthvarsProfile@timepoint_vals_chr"),
87+
timepoint_new_nms_chr = timepoint_new_nms_chr,
88+
what_1L_chr = "composite_mdl", write_1L_lgl = T)
89+
composite_2_plt <- depictSlot(x, slot_nm_1L_chr = "a_TTUSynopsis",
90+
what_1L_chr = "composite_utl", write_1L_lgl = T)
91+
if (!is.na(what_1L_chr)) {
92+
ggplot2::ggsave(file = paste0(dir_1L_chr, "/fig1",
93+
fl_type_1L_chr), composite_2_plt)
94+
ggplot2::ggsave(file = paste0(dir_1L_chr, "/fig2",
95+
fl_type_1L_chr), composite_1_plt)
96+
}
97+
}
3498
}
3599
})

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5646593.svg)](https://doi.org/10.5281/zenodo.5646593)
99
<!-- badges: end -->
1010

11-
Tools for developping, reporting and sharing Transfer To
11+
Tools for developing, reporting and sharing Transfer To
1212
Utility (TTU) mapping algorithms that predict health utility from
1313
other health measures. This development version of the TTU package
1414
has been made available as part of the process of testing and

_pkgdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ reference:
2222
- rprt_lup
2323
- title: "S4 Classes"
2424
- contents:
25+
- TTUSynopsis
2526
- TTUReports
2627
- title: "Methods"
2728
- contents:

data-raw/DATASET.R

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,27 @@ x <- ready4fun::make_pkg_desc_ls(pkg_title_1L_chr = "Implement Transfer to Utili
3838
zenodo_badge_1L_chr = "[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5646593.svg)](https://doi.org/10.5281/zenodo.5646593)")
3939
y <- ready4class::ready4class_constructor() %>%
4040
dplyr::bind_rows(ready4class::make_pt_ready4class_constructor(make_s3_lgl = FALSE,
41+
name_stub_chr = "Synopsis",
42+
slots_ls = list("a_Ready4showPaths",
43+
"b_SpecificResults",
44+
"c_SpecificParameters",
45+
"d_YouthvarsProfile",
46+
"e_Ready4useRepos") %>% list(),
47+
pt_ls = list("Ready4showPaths",
48+
"SpecificResults",
49+
"SpecificParameters",
50+
"YouthvarsProfile",
51+
"Ready4useRepos") %>% list(),
52+
class_desc_chr = "Input, Output and Authorship Data For Generating Utility Mapping Study Reports.",
53+
parent_class_chr = "SpecificSynopsis"),
54+
ready4class::make_pt_ready4class_constructor(make_s3_lgl = FALSE,
4155
name_stub_chr = "Reports",
42-
slots_ls = list("a_SpecificSynopsis",
56+
slots_ls = list("a_TTUSynopsis",
4357
"catalogue_tmpl_chr",
4458
"catalogue_fl_nms_ls",
4559
"manuscript_tmpl_chr",
4660
"manuscript_fl_nms_ls") %>% list(),
47-
pt_ls = list("SpecificSynopsis",
61+
pt_ls = list("TTUSynopsis",
4862
"character",
4963
"list",
5064
"character",
@@ -57,8 +71,8 @@ y <- ready4class::ready4class_constructor() %>%
5771
manuscript_fl_nms_ls = "ready4show::make_rmd_fl_nms_ls(pdf_fl_nm_1L_chr = \"Main_PDF\",
5872
word_fl_nm_1L_chr = \"Main_Word\")")),
5973
class_desc_chr = "Metadata to produce utility mapping study reports.",
60-
parent_class_chr = "Ready4Module"
61-
))
74+
parent_class_chr = "Ready4Module",
75+
inc_clss_ls = list("TTUSynopsis") %>% list()))
6276
datasets_ls <- list(tibble::tibble(short_name_chr = c("OLS_NTF",
6377
"OLS_LOG",
6478
"OLS_LOGIT",
@@ -161,9 +175,9 @@ z <- ready4pack::make_pt_ready4pack_manifest(x,
161175
z <- ready4::author(z)
162176
ready4::write_citation_cff(packageDescription("TTU"),
163177
citation_chr = readLines("inst/CITATION"))
164-
usethis::use_dev_package("specific",
165-
type = "Imports",
166-
remote = "ready4-dev/specific")
178+
# usethis::use_dev_package("specific",
179+
# type = "Imports",
180+
# remote = "ready4-dev/specific")
167181
# usethis::use_package("readr")
168182
# MANUAL DELETION OF TRAILING INCLUDE
169183
# usethis::use_dev_package("ready4",

data-raw/fns/get.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
get_pkg_citation <- function(pkg_nm_1L_chr){
2+
citation_chr <- suppressWarnings(citation(pkg_nm_1L_chr)) %>% capture.output()
3+
start_idx_1L_int <- 4
4+
end_idx_1L_int <- which(citation_chr== "")[which(which(citation_chr== "")>start_idx_1L_int)[1]]-1
5+
citation_1L_chr<- citation_chr[start_idx_1L_int:end_idx_1L_int] %>% paste0(collapse = "")
6+
return(citation_1L_chr)
7+
}

0 commit comments

Comments
 (0)