Skip to content

Commit

Permalink
added flexibility in NMgenText's processing of until argument
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Sep 6, 2024
1 parent 59d3963 commit b9b8415
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
15 changes: 11 additions & 4 deletions R/NMgenText.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions R/NMwriteData.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Expand Down
3 changes: 1 addition & 2 deletions R/mergeCheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions devel/check_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b9b8415

Please sign in to comment.