Skip to content

Commit

Permalink
aligning with common.cols arg
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Aug 19, 2024
1 parent e94a538 commit 73bc765
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions R/NMcheckData.R
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ NMcheckData <- function(data,file,covs,covs.occ,cols.num,col.id="ID",
if(!is.null(col.id)&&nrow(findings.row)>0){
if(col.id%in%colnames(findings.row)) findings.row[,(col.id):=NULL]

findings.row <- mergeCheck(findings.row,data[,c(c.row,col.id.orig),with=F],by.x="row",by.y=c.row,all.x=T,fun.commoncols=stop,quiet=TRUE)
findings.row <- mergeCheck(findings.row,data[,c(c.row,col.id.orig),with=F],by.x="row",by.y=c.row,all.x=T,common.cols=stop,quiet=TRUE)
setnames(findings.row,col.id.orig,col.id)
findings <- rbind(findings[level!="row"],findings.row,fill=T)

Expand All @@ -457,7 +457,7 @@ NMcheckData <- function(data,file,covs,covs.occ,cols.num,col.id="ID",
findings <- mergeCheck(findings,
data[,c(c.row,col.row.orig),with=F],
by.x="row",by.y=c.row,all.x=T,
fun.commoncols=stop,quiet=TRUE)
common.cols=stop,quiet=TRUE)
setnames(findings,col.row.orig,col.row)
}
if(!col.id%in%colnames(findings)) findings[,(col.id):=NA_real_]
Expand Down
4 changes: 2 additions & 2 deletions R/flagsAssign.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ flagsAssign <- function(data, tab.flags, subset.data, col.flagn, col.flagc,


dim0 <- dim(data.flags)
data.flags <- mergeCheck(data.flags,unique(tab.flags[,c("FLAG","flag")]),all.x=TRUE,by="FLAG",ncols.expect=1,fun.commoncols=base::stop,quiet=TRUE)
data.flags <- mergeCheck(data.flags,unique(tab.flags[,c("FLAG","flag")]),all.x=TRUE,by="FLAG",ncols.expect=1,common.cols=base::stop,quiet=TRUE)
## stopifnot(all(dim(data.flags)==(dim0+c(0,1))))

### rename FLAG and flag, and add back backed up columns if relevant
setnames(data.flags,c("FLAG","flag"),c(col.flagn,col.flagc))
## setnames(tab.flags,c("FLAG","flag"),c(col.flagn,col.flagc))
if(backed.up.old.flags){
data.flags <- mergeCheck(data.flags,flags.orig.data,by=col.row,fun.commoncols=base::stop,quiet=TRUE)
data.flags <- mergeCheck(data.flags,flags.orig.data,by=col.row,common.cols=base::stop,quiet=TRUE)
}

## add the data where flags have not been assigned
Expand Down
4 changes: 2 additions & 2 deletions R/mergeCheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
##' is a mistake, and the default is to throw a warning if this
##' happens. If using mergeCheck in programming, you may want to
##' make sure this is not happening and use
##' fun.commoncols=stop. If you want nothing to happen, you can do
##' fun.commoncols=NULL. You can also use `common.cols="drop.x"`
##' common.cols=stop. If you want nothing to happen, you can do
##' common.cols=NULL. You can also use `common.cols="drop.x"`
##' to drop "non-by" columns in `x` with identical column names in
##' `y`. Use "drop.y" to drop them in `y` and avoid the
##' conflicts. The last option is to use `common.cols="merge.by"`
Expand Down

0 comments on commit 73bc765

Please sign in to comment.