Skip to content

Commit e1b2bf2

Browse files
Merge pull request #225 from davraam/v6.0.1-dev
update ds.dataFrameFill to assign correct classes to the generated ve…
2 parents d618a20 + dc26981 commit e1b2bf2

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

R/ds.dataFrameFill.R

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ ds.dataFrameFill <- function(df.name=NULL, newobj=NULL, datasources=NULL){
116116
# if the datasets share the same variables then the function stops
117117
check.indicator <- c()
118118
for (i in 1:length(datasources)){
119-
if(length(column.names[[i]])==length(allNames)){check.indicator[i] <- 0}
120-
else{check.indicator[i] <- 1}
119+
if(length(setdiff(allNames,column.names[[i]])) > 0){
120+
check.indicator[i] <- 1
121+
}else{
122+
check.indicator[i] <- 0}
121123
}
122124

123125
if(sum(check.indicator)==0){
124-
stop("The dataframes have the same variables!", call.=FALSE)
126+
stop("The dataframes have the same variables. There are no missing variables to fill!", call.=FALSE)
125127
}
126128

127129
if(!is.null(allNames)){
@@ -130,7 +132,19 @@ ds.dataFrameFill <- function(df.name=NULL, newobj=NULL, datasources=NULL){
130132
allNames.transmit <- NULL
131133
}
132134

133-
calltext <- call("dataFrameFillDS", df.name, allNames.transmit)
135+
# get the class of each variable in the dataframes
136+
class.list <- lapply(allNames, function(x){dsBaseClient::ds.class(paste0(df.name, '$', x))})
137+
class.vect1 <- lapply(class.list, function(x){unlist(x)})
138+
class.vect2 <- lapply(class.vect1, function(x){x[which(x != 'NULL')[[1]]]})
139+
class.vect2 <- unname(unlist(class.vect2))
140+
141+
if(!is.null(class.vect2)){
142+
class.vect.transmit <- paste(class.vect2,collapse=",")
143+
}else{
144+
class.vect.transmit <- NULL
145+
}
146+
147+
calltext <- call("dataFrameFillDS", df.name, allNames.transmit, class.vect.transmit)
134148
DSI::datashield.assign(datasources, newobj, calltext)
135149

136150
#############################################################################################################

0 commit comments

Comments
 (0)