|
| 1 | +#' |
| 2 | +#' @title dataFrameFillDS |
| 3 | +#' @description An assign function called by the clientside ds.dataFrameFill function. |
| 4 | +#' @details This function checks if each study has all the variables compared to the other studies |
| 5 | +#' in the analysis. If a study does not have some of the variables, the function generates those |
| 6 | +#' variables as vectors of missing values and combines them as columns to the input data frame. |
| 7 | +#' Then, the "complete" in terms of the columns dataframe is saved in each server with a name |
| 8 | +#' specified by the argument \code{newobj} on the clientside. |
| 9 | +#' @param df.name a character string representing the name of the input data frame that will be |
| 10 | +#' filled with extra columns with missing values if a number of variables is missing from it |
| 11 | +#' compared to the data frames of the other studies used in the analysis. |
| 12 | +#' @param allNames.transmit unique names of all the variables that are included in the input |
| 13 | +#' data frames from all the used datasources. |
| 14 | +#' @return Nothing is returned to the client. The generated object is written to the serverside. |
| 15 | +#' @author Demetris Avraam for DataSHIELD Development Team |
| 16 | +#' @export |
| 17 | +#' |
| 18 | +dataFrameFillDS <- function(df.name, allNames.transmit){ |
| 19 | + |
| 20 | + datatext <- paste0("data.frame(",df.name,")") |
| 21 | + data <- eval(parse(text=datatext)) |
| 22 | + |
| 23 | + if(!is.null(allNames.transmit)){ |
| 24 | + allNames <- unlist(strsplit(allNames.transmit, split=",")) |
| 25 | + }else{ |
| 26 | + allNames <- NULL |
| 27 | + } |
| 28 | + |
| 29 | + study.colnames <- colnames(data) |
| 30 | + missingVars <- allNames[-which(allNames %in% study.colnames)] |
| 31 | + |
| 32 | + numRows <- dim(data)[1] |
| 33 | + numCols <- length(missingVars) |
| 34 | + |
| 35 | + mat.new <- matrix(NA, ncol=numCols, nrow=numRows) |
| 36 | + |
| 37 | + df.new <- as.data.frame(mat.new) |
| 38 | + colnames(df.new) <- missingVars |
| 39 | + df.new <- lapply(df.new, as.numeric) |
| 40 | + |
| 41 | + df.out <- cbind(data, df.new) |
| 42 | + |
| 43 | + return(df.out) |
| 44 | + |
| 45 | +} |
| 46 | +# ASSIGN FUNCTION |
| 47 | +# dataFrameFillDS |
| 48 | + |
0 commit comments