Skip to content

Commit

Permalink
Merge pull request #7 from metrumresearchgroup/release/0.2.0
Browse files Browse the repository at this point in the history
Release/0.2.0
  • Loading branch information
kylebaron authored Feb 20, 2020
2 parents a70733a + 9d543df commit faea3a9
Show file tree
Hide file tree
Showing 21 changed files with 499 additions and 71 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_pkgdown\.yml
Makefile
^test\.R$
^.*\.Rproj$
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
README.html
lastdose.Rcheck
lastdose*.tar.gz
Expand Down
12 changes: 7 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Package: lastdose
Type: Package
Title: Calculate Time and Amount of Last Dose
Version: 0.1.0
Author: Kyle Baron
Maintainer: Kyle Baron <kylebtwin@imap.cc>
Version: 0.2.0
Authors@R: c(
person("Kyle T", "Baron", email = "kyleb@metrumrg.com", role=c("aut", "cre"), comment=c(ORCID="0000-0001-7252-5656"))
)
Maintainer: Kyle T Baron <kyleb@metrumrg.com>
Description: Efficient calculation of time after last dose and last dose amount
for analysis data sets.
License: GPL (>=2)
LinkingTo: Rcpp
URL: https://github.com/kylebaron/lastdose
BugReports: https://github.com/kylebaron/lastdose/issues
URL: https://github.com/metrumresearchgroup/lastdose
BugReports: https://github.com/metrumresearchgroup/lastdose/issues
Suggests: testthat, Rcpp
Encoding: UTF-8
LazyData: true
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Generated by roxygen2: do not edit by hand

S3method(find_comments,character)
S3method(find_comments,data.frame)
export(find_comments)
export(lastdose)
export(lastdose_df)
export(lastdose_list)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

# lastdose 0.2.0
- Commented records are not considered when looking for doses in the data set,
but `TAD` and `LDOS` are filled like any other observation record (relative
to the last non-commented dose) #9

# lastdose 0.1.0

- Update git origin
Expand Down
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

lastdose_impl <- function(id, time, amt, evid, addl, ii, fill, back_calc, sort1) {
.Call(`_lastdose_lastdose_impl`, id, time, amt, evid, addl, ii, fill, back_calc, sort1)
lastdose_impl <- function(id, time, amt, evid, addl, ii, fill, back_calc, sort1, comment) {
.Call(`_lastdose_lastdose_impl`, id, time, amt, evid, addl, ii, fill, back_calc, sort1, comment)
}

89 changes: 84 additions & 5 deletions R/lastdose.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ NULL

#' Calculate last dose amount (LDOS) and time after last dose (TAD)
#'
#' Use [lastdose] to columns to the input data frame; [lastdose_list]
#' and [lastdose_df] returns calculated information as either
#' `list` or `data.frame` format without modifying the input data.
#' Use [lastdose] to add (or potentially replace) columns to the input
#' data frame; [lastdose_list] and [lastdose_df] returns calculated information
#' as either `list` or `data.frame` format without modifying the input data.
#'
#' @param data data set as data frame; see `details`
#' @param back_calc if `TRUE`, then the time before the first dose
Expand All @@ -21,12 +21,32 @@ NULL
#' concentration; if `dose_first` then the dose is assumed to be administered
#' and the observation made immediately after (with no advance in time). See
#' details.
#' @param comments a logcial vector with length equal to the number of rows
#' in `data` indicating which records are to be ignored when looking for `TAD`
#' and `LDOS`. See all the `fill_comments_na` argument.
#' @param ... arguments passed to [lastdose_list]
#' @param include_ldos `logical`; if `FALSE` then the `LDOS` data is not
#' appended to the data set. Only used for the [lastdose] function.
#'
#' @details
#'
#' When calling [lastdose] to modify the data frame, two columns will be
#' added (by default): `TAD` indicating the time after the most-recent dose
#' and `LDOS` indicating the amount of the most recent dose. This default
#' behavior can be modified with the `include_ldos` argument.
#'
#' When calling [lastdose_list] or [lastdose_df], the respective items are
#' accessible with `tad` and `ldos` (note the lower case form here to
#' distinguish from the columns that might be added to the data frame).
#'
#' **Handling of commented records**: Dosing records that have been "commented"
#' (as indicated with the `comments` argument) will never be considered as
#' actual doses when determining `TAD` and `LDOS`. But commented records (doses
#' and non-doses) will be assigned `TAD` and `LDOS` according to the last
#' non-commented dosing record.
#'
#' **Additional notes**:
#'
#' - All functions require an input data set as a data frame
#' - The data set should be formatted according to `NMTRAN` type
#' conventions
Expand Down Expand Up @@ -78,7 +98,14 @@ lastdose <- function(data,..., include_ldos = TRUE) {
#' @rdname lastdose
#' @export
lastdose_list <- function(data, fill = -99, back_calc = TRUE,
addl_ties = c("obs_first", "dose_first")) {
addl_ties = c("obs_first", "dose_first"),
comments = find_comments(data)) {
if(length(comments)==1) {
comments <- rep(comments,nrow(data))
}
if(!length(comments)==nrow(data)) {
stop("'comments' must be have length equal to the number of rows in 'data'",call.=FALSE)
}
addl_ties <- match.arg(addl_ties)
sort1 <- addl_ties == "obs_first"
x <- as.data.frame(data)
Expand Down Expand Up @@ -146,7 +173,8 @@ lastdose_list <- function(data, fill = -99, back_calc = TRUE,
col_ii,
fill,
back_calc,
sort1
sort1,
comments
)
ans
}
Expand All @@ -161,3 +189,54 @@ lastdose_df <- function(data,...) {
fix.empty.names=FALSE, row.names=NULL
)
}

#' Find commented records
#'
#' This function uses specific criteria for finding comment records that may
#' not match up with your coding conventions. See details below as well as
#' unit tests.
#'
#' @param x a data frame or character vector
#' @param ... not used
#'
#' @return
#' A logical vector
#'
#' @details
#' For the data frame method, comments are found in a column with name `C`
#' with type `character`. If a `C` column is found that is not character,
#' a warning is generated and no comments are found.
#'
#' For the character method or when an appropriate `C` column is found when
#' using the data frame method, a position or row is considered a comment
#' when it is either `NA` or when it is equal to `.`.
#'
#' @examples
#' comment <- c(NA, "C", "C", NA, ".", NA, "Comment")
#' dv <- rnorm(length(comment))
#' df <- data.frame(C = comment , DV = dv)
#'
#' find_comments(df)
#'
#'
#' @export
find_comments <- function(x,...) UseMethod("find_comments")
#' @rdname find_comments
#'
#' @export
find_comments.data.frame <- function(x,...) {
if(!is.character(x[["C"]])) {
if(exists("C", x)) {
warning("looking for comment records; found column 'C' but is wasn't character.")
}
return(vector(mode="logical", nrow(x)))
}
find_comments.character(x[["C"]])
}

#' @rdname find_comments
#' @export
find_comments.character <- function(x,...) {
!(is.na(x)|x=='.')
}

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ system.time(x2 <- lastdose(big))
```

. user system elapsed
. 0.048 0.001 0.050
. 0.045 0.002 0.047

## Compare against the single profile

Expand All @@ -172,7 +172,7 @@ system.time(x1 <- lastdose(df))
```

. user system elapsed
. 0.001 0.001 0.000
. 0.000 0.000 0.001

``` r
x3 <- filter(x2, big[["ID"]]==1) %>% as.data.frame()
Expand Down
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
development:
mode: auto
6 changes: 3 additions & 3 deletions docs/404.html

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

8 changes: 4 additions & 4 deletions docs/authors.html

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

16 changes: 8 additions & 8 deletions docs/index.html

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

16 changes: 12 additions & 4 deletions docs/news/index.html

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

Loading

0 comments on commit faea3a9

Please sign in to comment.