Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ export(ds.vectorCalc)
import(DSI)
import(data.table)
importFrom(DSI,datashield.connections_find)
importFrom(cli,cli_abort)
importFrom(cli,cli_inform)
importFrom(cli,cli_verbatim)
importFrom(cli,cli_warn)
importFrom(cli,
cli_abort,
cli_inform,
cli_verbatim,
cli_warn
)
importFrom(stats,
as.formula,
na.omit,
Expand Down
7 changes: 3 additions & 4 deletions R/checkClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
#' @param datasources a list of \code{\link[DSI]{DSConnection-class}} objects obtained after login. If the <datasources>
#' the default set of connections will be used: see \link[DSI]{datashield.connections_default}.
#' @param obj a string character, the name of the object to check for.
#' @param call The frame to report the error from.
#' @keywords internal
#' @return a message or the class of the object if the object has the same class in all studies.
#'
#'
checkClass <- function(datasources=NULL, obj=NULL){
checkClass <- function(datasources=NULL, obj=NULL, call=parent.frame()){
# check the class of the input object
cally <- call("classDS", obj)
classesBy <- DSI::datashield.aggregate(datasources, cally)

Check warning on line 17 in R/checkClass.R

View workflow job for this annotation

GitHub Actions / R lint (lintr)

file=R/checkClass.R,line=17,col=21,[namespace_linter] Don't use `::` to access datashield.aggregate, which is already imported from DSI.
classes <- unique(unlist(classesBy))
for (n in names(classesBy)) {
if (!all(classes == classesBy[[n]])) {
message("The input data is not of the same class in all studies!")
message("Use the function 'ds.class' to verify the class of the input object in each study.")
stop(" End of process!", call.=FALSE)
cli_abort(c("{.val {obj}} must have the same class in all studies.", .describeStudyClasses(classesBy)), call = call)
}
}
return(classes)
Expand Down
4 changes: 2 additions & 2 deletions R/ds.Boole.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ ds.Boole<-function(V1=NULL, V2=NULL, Boolean.operator=NULL, numeric.output=TRUE,
.checkArgProvided(V2, "the name of a column or scalar that holds V2")

# check if user has provided a Boolean operator in character format: eg '==' or '>=' or '<' or '!='
.checkArgProvided(Boolean.operator, "a Boolean operator in character format, such as '==' or '>='")
.checkArgProvided(Boolean.operator, "a Boolean operator in character format, such as \"==\" or \">=\"")

#check if na.assign has legal value
if(!(na.assign=="NA"||na.assign=="0"||na.assign=="1")){
Expand Down Expand Up @@ -151,7 +151,7 @@ ds.Boole<-function(V1=NULL, V2=NULL, Boolean.operator=NULL, numeric.output=TRUE,
}

if(BO.n == 0){
stop(paste0("An unrecognized Boolean operator, ", Boolean.operator, ", has provide"), call.=FALSE)
.abortInvalidChoice("Boolean.operator", c("==", "!=", "<", "<=", ">", ">="))
}

# if no value spcified for output object, then specify a default
Expand Down
7 changes: 5 additions & 2 deletions R/ds.asFactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@

# check if user has provided the name of the input variable in a correct character format
if(!is.character(input.var.name)){
stop("Please provide the name of the variable that is to be converted to a factor in character format e.g. 'varname'", call.=FALSE)
supplied <- .describeSupplied(input.var.name) # nolint: object_usage_linter. Used in the cli template
cli_abort("{.arg input.var.name} must be a character string, such as {.val varname}, not {supplied}.")
}

# if no output variable specified then provide a default name
Expand All @@ -206,7 +207,7 @@
#CALL THE FIRST SERVER SIDE FUNCTION (AN AGGREGATE FUNCTION)
#TO DETERMINE ALL OF THE LEVELS REQUIRED
calltext1 <- call("asFactorDS1", input.var.name)
all.levels <- DSI::datashield.aggregate(datasources, calltext1)

Check warning on line 210 in R/ds.asFactor.R

View workflow job for this annotation

GitHub Actions / R lint (lintr)

file=R/ds.asFactor.R,line=210,col=22,[namespace_linter] Don't use `::` to access datashield.aggregate, which is already imported from DSI.

failed.levels <- FALSE
for (levels in all.levels) {
Expand All @@ -215,7 +216,9 @@
failed.levels <- TRUE
}
if (failed.levels) {
stop("Failed to obtain levels: ", paste0(unlist(all.levels), collapse=", "), call. = TRUE)
messages <- unlist(all.levels)
bullets <- stats::setNames(paste0("{messages[", seq_along(messages), "]}"), rep("x", length(messages)))
cli_abort(c("Can't obtain the factor levels.", bullets))
}

numstudies <- length(datasources)
Expand All @@ -235,7 +238,7 @@
all.unique.levels.transmit <- paste0(all.unique.levels, collapse=",")

calltext2 <- call("asFactorDS2", input.var.name, all.unique.levels.transmit, fixed.dummy.vars, baseline.level)
DSI::datashield.assign(datasources, newobj.name, calltext2)

Check warning on line 241 in R/ds.asFactor.R

View workflow job for this annotation

GitHub Actions / R lint (lintr)

file=R/ds.asFactor.R,line=241,col=8,[namespace_linter] Don't use `::` to access datashield.assign, which is already imported from DSI.

return(list(all.unique.levels=all.unique.levels))

Expand Down
3 changes: 2 additions & 1 deletion R/ds.asFactorSimple.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

# check if user has provided the name of the input variable in a correct character format
if(!is.character(input.var.name)){
stop("Please provide the name of the variable that is to be converted to a factor in character format e.g. 'varname'", call.=FALSE)
supplied <- .describeSupplied(input.var.name) # nolint: object_usage_linter. Used in the cli template
cli_abort("{.arg input.var.name} must be a character string, such as {.val varname}, not {supplied}.")
}

# if no output variable specified then provide a default name
Expand All @@ -42,7 +43,7 @@

#Call the only serverside function required for this simple version of asFactor
calltext0 <- call("asFactorSimpleDS", input.var.name)
DSI::datashield.assign(datasources, newobj.name, calltext0)

Check warning on line 46 in R/ds.asFactorSimple.R

View workflow job for this annotation

GitHub Actions / R lint (lintr)

file=R/ds.asFactorSimple.R,line=46,col=8,[namespace_linter] Don't use `::` to access datashield.assign, which is already imported from DSI.

}
#ds.asFactorSimple
2 changes: 1 addition & 1 deletion R/ds.boxPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ds.boxPlot <- function(x, variables = NULL, group = NULL, group2 = NULL, xlabel
cls <- unique(unlist(cls))

if(!any(c("numeric", "data.frame") %in% cls)){
stop("The selected object is not a data frame nor a numerical vector")
cli_abort("{.arg x} must be a {.cls data.frame} or {.cls numeric} vector, not {.cls {cls}}.")
}

# Once all checks are passed, call the appropiate server functions
Expand Down
8 changes: 4 additions & 4 deletions R/ds.cbind.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,30 +146,30 @@ ds.cbind <- function(x=NULL, DataSHIELD.checks=FALSE, force.colnames=NULL, newob
next.class <- DSI::datashield.aggregate(datasources[std], calltext1)
class.vector <- c(class.vector, next.class[[1]])
if (notify.of.progress){
message("\n",j," of ", length(x), " elements to combine in step 1 of 2 in study ", std, "\n")
cli_inform("{j} of {length(x)} elements to combine in step 1 of 2 in {.val {names(datasources)[std]}}.")
}
}
for(j in 1:length(x)){
test.df <- x[j]
if(class.vector[j]!="data.frame" && class.vector[j]!="matrix"){
colname.vector <- c(colname.vector, test.df)
if (notify.of.progress){
message("\n",j," of ", length(x), " elements to combine in step 2 of 2 in study ", std, "\n")
cli_inform("{j} of {length(x)} elements to combine in step 2 of 2 in {.val {names(datasources)[std]}}.")
}
}else{
calltext2 <- call('colnamesDS', test.df)
df.names <- DSI::datashield.aggregate(datasources[std], calltext2)
colname.vector <- c(colname.vector, df.names[[1]])
if (notify.of.progress){
message("\n", j," of ", length(x), " elements to combine in step 2 of 2 in study ", std, "\n")
cli_inform("{j} of {length(x)} elements to combine in step 2 of 2 in {.val {names(datasources)[std]}}.")
}
}
}
colname.list[[std]] <- colname.vector
}

if (notify.of.progress){
message("\nBoth steps in all studies completed\n")
cli_inform("Both steps completed in all studies.")
}

# prepare name vectors for transmission
Expand Down
2 changes: 1 addition & 1 deletion R/ds.changeRefGroup.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ ds.changeRefGroup <- function(x=NULL, ref=NULL, newobj=NULL, reorderByRef=FALSE,
newobj <- .resolveNewobjName(newobj, "changerefgroup.newobj")

if(reorderByRef){
warning("'reorderByRef' is set to TRUE. Please read the documentation for possible consequences!", call.=FALSE)
cli_warn(c("{.arg reorderByRef} is {.code TRUE}, so the levels of {.val {x}} are reordered.", "!" = "Results are invalid if the new vector is added to a table that isn't reordered in the same way."))
}

# call the server side function that will recode the levels
Expand Down
4 changes: 2 additions & 2 deletions R/ds.contourPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ ds.contourPlot <- function(x=NULL, y=NULL, type='combine', show='all', numints=2

# print the number of invalid cells in each participating study
for (i in 1:num.sources) {
message(stdnames[i],': ', names(dimnames(grid.density.obj[[i]])[2]))
cli_inform("{.val {stdnames[i]}}: {names(dimnames(grid.density.obj[[i]])[2])}")
}

Global.grid.density <- matrix(0, dim(grid.density.obj[[1]])[1], numcol-2)
Expand Down Expand Up @@ -406,7 +406,7 @@ ds.contourPlot <- function(x=NULL, y=NULL, type='combine', show='all', numints=2

# print the number of invalid cells in each participating study
for (i in 1:num.sources) {
message(stdnames[i],': ', names(dimnames(grid.density.obj[[i]])[2]))
cli_inform("{.val {stdnames[i]}}: {names(dimnames(grid.density.obj[[i]])[2])}")
}

if(num.sources > 1){
Expand Down
2 changes: 1 addition & 1 deletion R/ds.cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ds.cor <- function(x=NULL, y=NULL, type="split", datasources=NULL, classConsiste
}

if(!is.null(y) && any(output[[1]]$class %in% c("matrix", "data.frame"))){
warning("x is a matrix or a dataframe; y will be ignored and a correlation matrix computed for x!")
cli_warn("{.arg x} is a {.cls matrix} or {.cls data.frame}, so {.arg y} is ignored and a correlation matrix is computed for {.arg x}.")
}

if (type=="split"){
Expand Down
2 changes: 1 addition & 1 deletion R/ds.cov.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ ds.cov <- function(x=NULL, y=NULL, naAction='pairwise.complete', type="split", d
}

if(!is.null(y) && any(output[[1]]$class %in% c("matrix", "data.frame"))){
warning("x is a matrix or a dataframe; y will be ignored and a covariance matrix computed for x!")
cli_warn("{.arg x} is a {.cls matrix} or {.cls data.frame}, so {.arg y} is ignored and a covariance matrix is computed for {.arg x}.")
}

if (type=="split"){
Expand Down
8 changes: 4 additions & 4 deletions R/ds.dataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,30 @@ ds.dataFrame <- function(x=NULL, row.names=NULL, check.rows=FALSE, check.names=T
next.class <- DSI::datashield.aggregate(datasources[std], calltext1)
class.vector <- c(class.vector, next.class[[1]])
if (notify.of.progress){
message("\n",j," of ", length(x), " elements to combine in step 1 of 2 in study ", std, "\n")
cli_inform("{j} of {length(x)} elements to combine in step 1 of 2 in {.val {names(datasources)[std]}}.")
}
}
for(j in 1:length(x)){
test.df <- x[j]
if(class.vector[j]!="data.frame" && class.vector[j]!="matrix"){
colname.vector <- c(colname.vector, test.df)
if (notify.of.progress){
message("\n",j," of ", length(x), " elements to combine in step 2 of 2 in study ", std, "\n")
cli_inform("{j} of {length(x)} elements to combine in step 2 of 2 in {.val {names(datasources)[std]}}.")
}
}else{
calltext2 <- call('colnamesDS', test.df)
df.names <- DSI::datashield.aggregate(datasources[std], calltext2)
colname.vector <- c(colname.vector, df.names[[1]])
if (notify.of.progress){
message("\n", j," of ", length(x), " elements to combine in step 2 of 2 in study ", std, "\n")
cli_inform("{j} of {length(x)} elements to combine in step 2 of 2 in {.val {names(datasources)[std]}}.")
}
}
}
colname.list[[std]] <- colname.vector
}

if (notify.of.progress){
message("\nBoth steps in all studies completed\n")
cli_inform("Both steps completed in all studies.")
}

# prepare vectors for transmission
Expand Down
21 changes: 7 additions & 14 deletions R/ds.dataFrameSubset.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ ds.dataFrameSubset<-function(df.name=NULL, V1.name=NULL, V2.name=NULL, Boolean.o

if(is.null(keep.cols)&&is.null(rm.cols)&&is.null(V1.name))
{
stop("Please provide the name of the column or scalar that holds V1 as a character string: eg 'xxx' or '3'", call.=FALSE)
cli_abort("{.arg V1.name} must name a column or scalar as a character string, not {.code NULL}, unless you are subsetting only columns.")
}

if((!is.null(keep.cols)||!is.null(rm.cols))&&is.null(V1.name))
Expand All @@ -136,7 +136,7 @@ ds.dataFrameSubset<-function(df.name=NULL, V1.name=NULL, V2.name=NULL, Boolean.o

if(is.null(keep.cols)&&is.null(rm.cols)&&is.null(V2.name))
{
stop("Please provide the name of the column or scalar that holds V2 as a character string: eg 'xxx' or '3'", call.=FALSE)
cli_abort("{.arg V2.name} must name a column or scalar as a character string, not {.code NULL}, unless you are subsetting only columns.")
}

if((!is.null(keep.cols)||!is.null(rm.cols))&&is.null(V2.name))
Expand All @@ -146,15 +146,8 @@ ds.dataFrameSubset<-function(df.name=NULL, V1.name=NULL, V2.name=NULL, Boolean.o

if(is.null(keep.cols)&&is.null(rm.cols)&&is.null(Boolean.operator))
{
message1<-"Unless you are only subsetting columns, please provide a"
message2<-"Boolean operator in character format: eg '==' or '>=' or '<' or '!='."
message3<-"However, if either keep.cols or rm.cols is non-null because you want"
message4<-"to subset columns and you specify both V1.name and V2.name as NULL (or 'ONES')"
message5<-"and Boolean.operator as NULL,ds.dataFrameSubset will subset out"
message6<-"the specified columns but will keep all rows."

error.message<-paste(message1,message2,message3,message4,message5,message6)
stop(error.message, call.=FALSE)
cli_abort(c("{.arg Boolean.operator} must be a Boolean operator in character format, such as {.val ==} or {.val >=}, not {.code NULL}, unless you are subsetting only columns.", "i" = "If {.arg keep.cols} or {.arg rm.cols} is set and {.arg V1.name}, {.arg V2.name} and {.arg Boolean.operator} are all {.code NULL}, the specified columns are subset and all rows are kept."))
}

if((!is.null(keep.cols)||!is.null(rm.cols))&&is.null(Boolean.operator))
Expand Down Expand Up @@ -217,13 +210,13 @@ if(!is.null(rm.cols)){
if (notify.of.progress)
{
if(num.messages==1){
message("\nSource",s,"\n",return.warning.message[[s]][[1]],"\n")
cli_inform(c("Source {s}", "{return.warning.message[[s]][[1]]}"))
}else{
message("\nSource",s,"\n")
cli_inform("Source {s}")
for(m in 1:(num.messages-1)){
message(return.warning.message[[s]][[m]],"\n")
cli_inform("{return.warning.message[[s]][[m]]}")
}
message(return.warning.message[[s]][[num.messages]],"\n")
cli_inform("{return.warning.message[[s]][[num.messages]]}")
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions R/ds.densityGrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,14 @@ ds.densityGrid <- function(x=NULL, y=NULL, numints=20, type='combine', datasourc

# print the number of invalid cells in each participating study
for (i in 1:num.sources){
message(stdnames[i],': ', names(dimnames(grid.density.obj[[i]])[2]))
cli_inform("{.val {stdnames[i]}}: {names(dimnames(grid.density.obj[[i]])[2])}")
}

Global.grid.density <- matrix(0, dim(grid.density.obj[[1]])[1], numcol-2)
for (i in 1:num.sources){
Global.grid.density <- Global.grid.density + grid.density.obj[[i]][,1:(numcol-2)]
names(dimnames(Global.grid.density))[2] <- "Grid Density Matrix of the Pooled Data"
}
# newline for some space between the previous messages and the matrix when it is displayed
message()
return(Global.grid.density)
}else{
if(type=="split"){
Expand All @@ -157,7 +155,7 @@ ds.densityGrid <- function(x=NULL, y=NULL, numints=20, type='combine', datasourc

# print the number of invalid cells in each participating study
for (i in 1:num.sources){
message(stdnames[i],': ', names(dimnames(grid.density.obj[[i]])[2]))
cli_inform("{.val {stdnames[i]}}: {names(dimnames(grid.density.obj[[i]])[2])}")
}
return(grid.density.obj)
}else{
Expand Down
3 changes: 2 additions & 1 deletion R/ds.dmtC2S.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ if(dplyr::is.tbl(dfdata))

if(!is.matrix(dfdata) && !is.data.frame(dfdata) && !dplyr::is.tbl(dfdata))
{
cli_abort("{.arg dfdata} must be a data.frame, matrix or tibble.")
supplied <- .describeSupplied(dfdata) # nolint: object_usage_linter. Used in the cli template
cli_abort("{.arg dfdata} must be a {.cls data.frame}, {.cls matrix}, or {.cls tbl_df}, not {supplied}.")
}

inout.object.transmit<-paste0(as.character(inout.object),collapse=",")
Expand Down
2 changes: 1 addition & 1 deletion R/ds.elspline.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ds.elspline <- function(x, n, marginal = FALSE, names = NULL, newobj = NULL, dat
.checkArgProvided(n, "a number of knots")

if(n < 2){
stop("'n' must be a value greater than or equal to 2!", call.=FALSE)
cli_abort("{.arg n} must be greater than or equal to 2, not {.val {n}}.")
}

# create a name by default if user did not provide a name for the new variable
Expand Down
2 changes: 1 addition & 1 deletion R/ds.forestplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ds.forestplot <- function(mod, variable = NULL, method = "ML", layout = "JAMA"){
if(variables[1] == "(Intercept)"){variable <- variables[2]} else {variable <- variables[1]}
} else { # Check supplied variable exists
if(!(variable %in% variables)){
stop("[", variable, "] is not valid. Valid variables [", paste(variables, collapse = ", "), "]")
.abortInvalidChoice("variable", variables)
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/ds.gamlss.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ds.gamlss <- function(formula = NULL, sigma.formula = '~1', nu.formula = '~1',
# }

if(centiles==TRUE & is.null(xvar)){
stop("Provide the name of the explanatory variable in 'xvar' argument", call.=FALSE)
cli_abort("{.arg xvar} must name the explanatory variable when {.arg centiles} is {.code TRUE}, not {.code NULL}.")
}

newobj <- .resolveNewobjName(newobj, 'gamlss_res')
Expand Down
5 changes: 3 additions & 2 deletions R/ds.getWGSR.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ ds.getWGSR <- function(sex=NULL, firstPart=NULL, secondPart=NULL, index=NULL, st

# If 'thirdPart' (age) is missing for BMI-for-age return an error message
if(index == "bfa" & is.na(thirdPart)) {
stop("'thirdPart' variable should not be missing for index 'bfa'", call.=FALSE)
cli_abort("{.arg thirdPart} must be provided when {.arg index} is {.val bfa}, not {.code NA}.")
}

# If 'standing' is not a value either 1, 2, 3, or NA return an error message
if(!any(standing %in% c(NA, 1, 2, 3))) {
stop("The 'standing' variable must be a numeric value either 1, 2, or 3!", call.=FALSE)
supplied <- .describeSupplied(standing) # nolint: object_usage_linter. Used in the cli template
cli_abort("{.arg standing} must be {.or {.val {1:3}}}, not {supplied}.")
}

# check newobj not actively declared as null
Expand Down
Loading
Loading