Skip to content

Commit

Permalink
adding some basic docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
brycefrank committed Sep 25, 2024
1 parent 50c0057 commit 2d29d34
Show file tree
Hide file tree
Showing 29 changed files with 455 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(get_params_path)
export(ingest_models)
export(load_parameter_frame)
export(map_publications)
export(set_params_path)
importFrom(magrittr,"%>%")
9 changes: 9 additions & 0 deletions R/connection.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#' Establish a connection to the models collection
#'
#' @param url A mongodb url connection string
get_model_con <- function(url) {
mongolite::mongo(
url = url, db = "allodev", collection = "models"
)
}

#' Establish a connection to the publications collection
#'
#' @param url A mongodb url connection string
get_pub_con <- function(url) {
mongolite::mongo(
url = url, db = "allodev", collection = "publications"
)
}

#' Establish a connection to the update collection
#'
#' @param url A mongodb url connection string
get_update_con <- function(url) {
mongolite::mongo(
url = url, db = "allodev", collection = "update"
Expand Down
7 changes: 7 additions & 0 deletions R/file_mod.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#' Parse parameter file names for publication IDs
#'
#' @param filenames A vector of parameter CSV filenames (including extension)
#' @return A vector of unique publication IDs
parse_parameter_names <- function(filenames) {
pattern <- "(?:.*_)?([a-zA-Z]+)_(\\d{4}[a-zA-Z]?)(?:_.*)?\\.csv"
matches <- stringr::str_match(filenames, pattern)
Expand All @@ -9,6 +13,9 @@ parse_parameter_names <- function(filenames) {
}
}

#' Get publication IDs modified since a specified commit
#'
#' @param last_commit The commit ID to check to
get_modified_files <- function(last_commit) {
sys_string <- paste0("git diff --name-only ", last_commit, " HEAD")
files <- system(sys_string, intern = TRUE)
Expand Down
46 changes: 46 additions & 0 deletions R/json.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#' Convert citation authors to JSON
#'
#' @param authors A list of Person objects
#' @return A list containing each author, with `given` and `family` name fields
authors_to_json <- function(authors) {
out <- list()

Expand All @@ -13,6 +17,11 @@ authors_to_json <- function(authors) {
out
}

#' Convert citation to JSON
#'
#' @param citation The citation of a publication, as a `RefManageR::BibEntry`
#' object
#' @return A JSON representation of the citation
citation_to_json <- function(citation) {
# Prepare output list with required fields
unclassed_citation <- attributes(unclass(citation)[[1]])
Expand Down Expand Up @@ -47,6 +56,11 @@ citation_to_json <- function(citation) {
required
}

#' Convert variables to JSON
#'
#' @param variables A list containing variables, via `response` or `covariates`
#' slots of a model
#' @return A list of parsed variables
variables_to_json <- function(variables) {
variable_names <- names(variables)
out <- list()
Expand All @@ -61,6 +75,10 @@ variables_to_json <- function(variables) {
out
}

#' Unbox the elements of a nested list
#'
#' @param object A nested list
#' @return A list with nested elements unboxed
unbox_nested <- function(object) {
for(i in 1:length(object)) {
for(j in 1:length(object[[i]])) {
Expand All @@ -70,6 +88,10 @@ unbox_nested <- function(object) {
object
}

#' Unbox the elements of a list
#'
#' @param object A nonnested list
#' @return A list with each element unboxed
unbox_nonnested <- function(object) {
for(i in 1:length(object)) {
object[[i]] <- jsonlite::unbox(object[[i]])
Expand All @@ -78,6 +100,10 @@ unbox_nonnested <- function(object) {
object
}

#' Convert a taxa object to JSON
#'
#' @param taxa An `allometric::Taxa()` object
#' @return A list of taxons in list format
taxa_to_json <- function(taxa) {
out <- list()

Expand All @@ -94,6 +120,10 @@ taxa_to_json <- function(taxa) {
out
}

#' Convert descriptors to JSON
#'
#' @param descriptors A list containing descriptors
#' @return A list containing descriptors converted to JSON format
descriptors_to_json <- function(descriptors) {
descriptors_list <- as.list(descriptors)
if(length(descriptors_list) == 0) {
Expand All @@ -114,6 +144,10 @@ descriptors_to_json <- function(descriptors) {
descriptors_list
}

#' Generate an inline citation
#'
#' @param citation A `RefManageR::BibEntry` object
#' @return A string containing the inline citation
prepare_inline_citation <- function(citation) {
n_authors <- length(citation$author)

Expand Down Expand Up @@ -147,6 +181,10 @@ prepare_inline_citation <- function(citation) {
out
}

#' Parse a function into a string
#'
#' @param func_body The body of a function
#' @return A string representation of the function
parse_func_body <- function(func_body) {
body_list <- as.list(body(func_body))[-1]
body_characters <- c()
Expand All @@ -162,6 +200,10 @@ parse_func_body <- function(func_body) {
body_characters
}

#' Convert covariate definitions to JSON
#'
#' @param covt_def_data A list of covariate definitions
#' @return A list of covariate definitions parsable to JSON
covariate_definitions_to_json <- function(covt_def_data) {
if(length(covt_def_data) == 0) {
return(list())
Expand All @@ -181,6 +223,10 @@ covariate_definitions_to_json <- function(covt_def_data) {
}
}

#' Convert model to JSON
#'
#' @param model A model object, i.e., `allometric::FixedEffectsModel()`
#' @return A list containing a parsable form of the model object
model_to_json <- function(model) {
proxy_id <- get_model_hash(
model@predict_fn_populated, model@descriptors
Expand Down
17 changes: 17 additions & 0 deletions man/authors_to_json.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions man/citation_to_json.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/covariate_definitions_to_json.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/delete_pub.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/delete_pubs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/descriptors_to_json.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/get_current_pub_ids.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/get_current_pub_ids_params.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/get_model_con.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/get_modified_files.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/get_pub_con.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/get_update_con.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/map_publications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/model_to_json.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2d29d34

Please sign in to comment.