From b9b8415a6950498cb2898bf1598027a3b2e6c31d Mon Sep 17 00:00:00 2001 From: Philip Delff Date: Fri, 6 Sep 2024 16:04:11 -0400 Subject: [PATCH] added flexibility in NMgenText's processing of until argument --- R/NMgenText.R | 15 +++++++++++---- R/NMwriteData.R | 12 ++++++++++-- R/mergeCheck.R | 3 +-- devel/check_package.R | 1 + 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/R/NMgenText.R b/R/NMgenText.R index 566210a3..24b7b441 100644 --- a/R/NMgenText.R +++ b/R/NMgenText.R @@ -143,7 +143,7 @@ NMgenText <- function(data, } } - if(allow.char.TIME){ + if(allow.char.TIME){ if("DATE"%in%colnames(data) && as.num.ok[,DATE==FALSE]) { as.num.ok[,DATE:=TRUE] @@ -169,15 +169,22 @@ NMgenText <- function(data, ## apply "until" if(!missing(until) && !is.null(until)){ + if(!is.numeric(until)&&!is.character(until)){ messageWrap("until must be either numeric or character.") } if(is.character(until)){ ## convert to numeric + until <- match(until,dt.num.ok[,name.nm]) } - until <- max(until) - dt.num.ok <- dt.num.ok[1:until] + until <- until[!is.na(until)] + if(length(until)){ + until <- max(until) + dt.num.ok <- dt.num.ok[1:until] + } else { + message("No recognized variables in \'until\'. Ignoring.") + } } ## apply DROP @@ -234,7 +241,7 @@ NMgenText <- function(data, text.nm.input <- strwrap( text.nm.input ) - } else if(width>0){ + } else if(width>0){ text.nm.input <- strwrap( text.nm.input ,width=width diff --git a/R/NMwriteData.R b/R/NMwriteData.R index 096e7622..c39fae26 100644 --- a/R/NMwriteData.R +++ b/R/NMwriteData.R @@ -307,8 +307,16 @@ NMwriteData <- function(data,file,formats.write=c("csv","rds"), if(any(!comma.ok)){ - messageWrap(paste("When writing csv, You must avoid commas in data values. They will corrupt the csv file. Either 1) avoid csv using `formats.write=\"rds\"` or 2) drop columns containing commas or 3) remove or replace commas in data values before saving data. For 3) see `?editCharCols`.\nComma found in column(s):",paste(colnames(data.dt)[comma.ok==FALSE],sep=", ")), - fun.msg=stop) + messageWrap( + "When writing csv, You must avoid commas in data values. They will corrupt the csv file. You can + +1) avoid csv using formats.write=\"rds\" or +2) drop columns containing commas or +3) remove or replace commas in data values before saving data. ?editCharCols can help with option 3.", + paste(" + +Comma found in column(s):",paste(colnames(data.dt)[comma.ok==FALSE],collapse=", ")), + fun.msg=stop) } } diff --git a/R/mergeCheck.R b/R/mergeCheck.R index 7ea881e4..bbaeb762 100644 --- a/R/mergeCheck.R +++ b/R/mergeCheck.R @@ -125,9 +125,8 @@ ##' dt.cov <- pk[,.(ID=unique(ID))] ##' dt.cov[,COV:=sample(1:5,size=.N,replace=TRUE)] ##' dt.cov <- dt.cov[c(1,1:(.N-1))] -##' dim(pk) ##' res.merge <- merge(pk,dt.cov,by="ID") -##' dim(res.merge) +##' dims(pk,dt.cov,res.merge) ##' mergeCheck(pk,dt.cov,by="ID") ##' } ##' @export diff --git a/devel/check_package.R b/devel/check_package.R index 3d893321..d3b542d9 100644 --- a/devel/check_package.R +++ b/devel/check_package.R @@ -2,6 +2,7 @@ remotes::install_github("thinkr-open/checkhelper") library(checkhelper) path.pkg <- "~/wdirs/NMdata" finds <- find_missing_tags(path.pkg) +as.data.table(finds) file.csv <- tempfile() fwrite(finds,file=file.csv) as.data.table(finds)