Skip to content

Commit

Permalink
Rename linelist -> datatagr
Browse files Browse the repository at this point in the history
Occurrences of linelist are replaced when not indicative of actual linelist references.
  • Loading branch information
chartgerink committed Jul 25, 2024
1 parent ea62810 commit 3f628b0
Show file tree
Hide file tree
Showing 59 changed files with 411 additions and 411 deletions.
18 changes: 9 additions & 9 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Generated by roxygen2: do not edit by hand

S3method("$<-",linelist)
S3method("[",linelist)
S3method("[<-",linelist)
S3method("[[<-",linelist)
S3method("names<-",linelist)
S3method(print,linelist)
S3method(select,linelist)
S3method("$<-",datatagr)
S3method("[",datatagr)
S3method("[<-",datatagr)
S3method("[[<-",datatagr)
S3method("names<-",datatagr)
S3method(print,datatagr)
S3method(select,datatagr)
export(get_lost_tags_action)
export(has_tag)
export(lost_tags_action)
export(make_linelist)
export(make_datatagr)
export(select_tags)
export(set_tags)
export(tags)
export(tags_defaults)
export(tags_df)
export(tags_names)
export(tags_types)
export(validate_linelist)
export(validate_datatagr)
export(validate_tags)
export(validate_types)
importFrom(dplyr,select)
Expand Down
14 changes: 7 additions & 7 deletions R/datatagr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#'
#' @section Main functions:
#'
#' * [make_linelist()]: to create `datatagr` objects from a `data.frame` or a
#' * [make_datatagr()]: to create `datatagr` objects from a `data.frame` or a
#' `tibble`
#'
#' * [set_tags()]: to change or add tagged variables in a `datatagr`
Expand All @@ -35,7 +35,7 @@
#' * `names() <-` (and related functions, such as [dplyr::rename()]) will
#' rename tags as needed
#'
#' * `x[...] <-` and `x[[...]] <-` (see [sub_linelist]): will adopt the
#' * `x[...] <-` and `x[[...]] <-` (see [sub_datatagr]): will adopt the
#' desired behaviour when tagged variables are lost
#'
#' * `print()`: prints info about the `datatagr` in addition to the
Expand All @@ -46,11 +46,11 @@
#' if (require(outbreaks)) {
#' # using base R style
#'
#' ## dataset we'll create a linelist from, only using the first 50 entries
#' ## dataset we'll create a datatagr from, only using the first 50 entries
#' measles_hagelloch_1861[1:50, ]
#'
#' ## create linelist
#' x <- make_linelist(measles_hagelloch_1861[1:50, ],
#' ## create datatagr
#' x <- make_datatagr(measles_hagelloch_1861[1:50, ],
#' id = "case_ID",
#' date_onset = "date_of_prodrome",
#' age = "age",
Expand Down Expand Up @@ -82,13 +82,13 @@
#'
#' # using tidyverse style
#'
#' ## example of creating a linelist, adding a new variable, and adding a tag
#' ## example of creating a datatagr, adding a new variable, and adding a tag
#' ## for it
#'
#' if (require(dplyr) && require(magrittr)) {
#' x <- measles_hagelloch_1861 %>%
#' tibble() %>%
#' make_linelist(
#' make_datatagr(
#' id = "case_ID",
#' date_onset = "date_of_prodrome",
#' age = "age",
Expand Down
24 changes: 24 additions & 0 deletions R/drop_datatagr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' Remove the datatagr class from an object
#'
#' Internal function. Used for dispatching to other methods when `NextMethod` is
#' an issue (typically to pass additional arguments to the `datatagr` method).
#'
#' @param x a `datatagr` object
#'
#' @param remove_tags a `logical` indicating if tags should be removed from the
#' attributes; defaults to `TRUE`
#'
#' @noRd
#'
#' @return The function returns the same object without the `datatagr` class.
#'
#'

drop_datatagr <- function(x, remove_tags = TRUE) {
classes <- class(x)
class(x) <- setdiff(classes, "datatagr")
if (remove_tags) {
attr(x, "tags") <- NULL
}
x
}
24 changes: 0 additions & 24 deletions R/drop_linelist.R

This file was deleted.

6 changes: 3 additions & 3 deletions R/has_tag.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#'
#' @examples
#' if (require(outbreaks) && require(dplyr)) {
#' ## dataset we'll create a linelist from
#' ## dataset we'll create a datatagr from
#' measles_hagelloch_1861
#'
#' ## create linelist
#' x <- make_linelist(measles_hagelloch_1861,
#' ## create datatagr
#' x <- make_datatagr(measles_hagelloch_1861,
#' id = "case_ID",
#' date_onset = "date_of_prodrome",
#' age = "age",
Expand Down
20 changes: 10 additions & 10 deletions R/lost_tags_action.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Check and set behaviour for lost tags
#'
#' This function determines the behaviour to adopt when tagged variables of a
#' `linelist` are lost e.g. through subsetting. This is achieved using `options`
#' defined for the `linelist` package.
#' `datatagr` are lost e.g. through subsetting. This is achieved using `options`
#' defined for the `datatagr` package.
#'
#' @param action a `character` indicating the behaviour to adopt when tagged
#' variables have been lost: "error" (default) will issue an error; "warning"
Expand All @@ -13,10 +13,10 @@
#'
#' @param x deprecated
#'
#' @return returns `NULL`; the option itself is set in `options("linelist")`
#' @return returns `NULL`; the option itself is set in `options("datatagr")`
#'
#' @details The errors or warnings generated by linelist in case of tagged
#' variable loss has a custom class of `linelist_error` and `linelist_warning`
#' @details The errors or warnings generated by datatagr in case of tagged
#' variable loss has a custom class of `datatagr_error` and `datatagr_warning`
#' respectively.
#'
#' @export
Expand Down Expand Up @@ -46,18 +46,18 @@
lost_tags_action <- function(action = c("warning", "error", "none"),
quiet = FALSE,
x) {
if (!missing(x) || inherits(action, "linelist")) {
if (!missing(x) || inherits(action, "datatagr")) {
stop(
"Using `lost_tags_action()` in a pipeline is deprecated",
call. = FALSE
)
}

linelist_options <- options("linelist")$linelist # nolint
datatagr_options <- options("datatagr")$datatagr # nolint

action <- match.arg(action)
linelist_options$lost_tags_action <- action
options(linelist = linelist_options) # nolint
datatagr_options$lost_tags_action <- action
options(datatagr = datatagr_options) # nolint
if (!quiet) {
if (action == "warning") msg <- "Lost tags will now issue a warning."
if (action == "error") msg <- "Lost tags will now issue an error."
Expand All @@ -74,5 +74,5 @@ lost_tags_action <- function(action = c("warning", "error", "none"),
#' @rdname lost_tags_action

get_lost_tags_action <- function() {
options("linelist")$linelist$lost_tags_action # nolint
options("datatagr")$datatagr$lost_tags_action # nolint
}
24 changes: 12 additions & 12 deletions R/make_linelist.R → R/make_datatagr.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#' Create a linelist from a data.frame
#' Create a datatagr from a data.frame
#'
#' This function converts a `data.frame` or a `tibble` into a `linelist` object,
#' This function converts a `data.frame` or a `tibble` into a `datatagr` object,
#' where different types of epidemiologically relevant data are tagged. This
#' includes dates of different events (e.g. onset of symptoms, case reporting),
#' information on the patient (e.g. age, gender, location) as well as other
#' information such as the type of case (e.g. confirmed, probable) or the
#' outcome of the disease. The output will seem to be the same `data.frame`, but
#' `linelist`-aware packages will then be able to automatically use tagged
#' `datatagr`-aware packages will then be able to automatically use tagged
#' fields for further data cleaning and analysis.
#'
#' @param x a `data.frame` or a `tibble` containing case line list data, with
Expand All @@ -18,15 +18,15 @@
#' details for a list of known variable types and their expected content
#'
#' @param allow_extra a `logical` indicating if additional data tags not
#' currently recognized by `linelist` should be allowed; if `FALSE`, unknown
#' currently recognized by `datatagr` should be allowed; if `FALSE`, unknown
#' tags will trigger an error
#'
#' @seealso
#'
#' * An overview of the [datatagr] package
#' * [tags_names()]: for a list of known tag names
#' * [tags_types()]: for the associated accepted types/classes
#' * [tags()]: for a list of tagged variables in a `linelist`
#' * [tags()]: for a list of tagged variables in a `datatagr`
#' * [set_tags()]: for modifying tags
#' * [tags_df()]: for selecting variables by tags
#'
Expand Down Expand Up @@ -73,16 +73,16 @@
#'
#' @export
#'
#' @return The function returns a `linelist` object.
#' @return The function returns a `datatagr` object.
#'
#' @examples
#'
#' if (require(outbreaks)) {
#' ## dataset we will convert to linelist
#' ## dataset we will convert to datatagr
#' head(measles_hagelloch_1861)
#'
#' ## create linelist
#' x <- make_linelist(measles_hagelloch_1861,
#' ## create datatagr
#' x <- make_datatagr(measles_hagelloch_1861,
#' id = "case_ID",
#' date_onset = "date_of_prodrome",
#' age = "age",
Expand All @@ -102,13 +102,13 @@
#' age = "age",
#' gender = "gender"
#' )
#' new_x <- make_linelist(measles_hagelloch_1861, !!!my_tags)
#' new_x <- make_datatagr(measles_hagelloch_1861, !!!my_tags)
#'
#' ## The output is strictly equivalent to the previous one
#' identical(x, new_x)
#' }
#'
make_linelist <- function(x,
make_datatagr <- function(x,
...,
allow_extra = FALSE) {
# assert inputs
Expand Down Expand Up @@ -139,6 +139,6 @@ make_linelist <- function(x,
x <- tag_variables(x, tags)

# shape output and return object
class(x) <- c("linelist", class(x))
class(x) <- c("datatagr", class(x))
x
}
18 changes: 9 additions & 9 deletions R/names.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#' Rename columns of a linelist
#' Rename columns of a datatagr
#'
#' This function can be used to rename the columns a `linelist`, adjusting tags
#' This function can be used to rename the columns a `datatagr`, adjusting tags
#' as needed.
#'
#' @param x a `linelist` object
#' @param x a `datatagr` object
#'
#' @param value a `character` vector to set the new names of the columns of `x`
#'
#' @return a `linelist` with new column names
#' @return a `datatagr` with new column names
#'
#' @export
#'
#' @examples
#' if (require(outbreaks)) {
#' ## dataset to create a linelist from
#' ## dataset to create a datatagr from
#' measles_hagelloch_1861
#'
#' ## create linelist
#' x <- make_linelist(measles_hagelloch_1861,
#' ## create datatagr
#' x <- make_datatagr(measles_hagelloch_1861,
#' id = "case_ID",
#' date_onset = "date_of_prodrome",
#' age = "age",
Expand All @@ -41,7 +41,7 @@
#' tags(x)
#' }
#' }
`names<-.linelist` <- function(x, value) {
`names<-.datatagr` <- function(x, value) {
# Strategy for renaming

# Since renaming cannot drop columns, we can update tags to match new variable
Expand All @@ -50,7 +50,7 @@
# 1. Storing old names and new names to have define replacement rules
# 2. Replace all tagged variables using the replacement rules

out <- drop_linelist(x, remove_tags = TRUE)
out <- drop_datatagr(x, remove_tags = TRUE)
names(out) <- value

# Step 1
Expand Down
20 changes: 10 additions & 10 deletions R/print.linelist.R → R/print.datatagr.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Printing method for linelist objects
#' Printing method for datatagr objects
#'
#' This function prints linelist objects.
#' This function prints datatagr objects.
#'
#' @param x a `linelist` object
#' @param x a `datatagr` object
#'
#' @param ... further arguments to be passed to 'print'
#'
Expand All @@ -12,11 +12,11 @@
#'
#' @examples
#' if (require(outbreaks)) {
#' ## dataset we'll create a linelist from
#' ## dataset we'll create a datatagr from
#' measles_hagelloch_1861
#'
#' ## create linelist
#' x <- make_linelist(measles_hagelloch_1861,
#' ## create datatagr
#' x <- make_datatagr(measles_hagelloch_1861,
#' id = "case_ID",
#' date_onset = "date_of_prodrome",
#' age = "age",
Expand All @@ -30,17 +30,17 @@
#' if (require(tibble) && require(magrittr)) {
#' measles_hagelloch_1861 %>%
#' tibble() %>%
#' make_linelist(
#' make_datatagr(
#' id = "case_ID",
#' date_onset = "date_of_prodrome",
#' age = "age",
#' gender = "gender"
#' )
#' }
#' }
print.linelist <- function(x, ...) {
cat("\n// linelist object\n")
print(drop_linelist(x, remove_tags = TRUE))
print.datatagr <- function(x, ...) {
cat("\n// datatagr object\n")
print(drop_datatagr(x, remove_tags = TRUE))
tags_txt <- paste(names(tags(x)), unlist(tags(x)), sep = ":", collapse = ", ")
if (tags_txt == "") {
tags_txt <- "[no tagged variable]"
Expand Down
Loading

0 comments on commit 3f628b0

Please sign in to comment.