Skip to content

Commit ebd8789

Browse files
committed
refactor: lengthDS and numNaDS return class for consistency checking
1 parent c5b9673 commit ebd8789

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

R/lengthDS.R

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
#' @description This function is similar to R function \code{length}.
44
#' @details The function returns the length of the input vector or list.
55
#' @param x a string character, the name of a vector or list
6-
#' @return a numeric, the number of elements of the input vector or list.
6+
#' @return a list with two elements: \code{length} (the number of elements of the input
7+
#' vector or list) and \code{class} (the class of the input object, for client-side
8+
#' consistency checking)
79
#' @author Demetris Avraam, for DataSHIELD Development Team
10+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
811
#' @export
912
#'
1013
lengthDS <- function(x){
11-
12-
x.var <- eval(parse(text=x), envir = parent.frame())
13-
14-
# find the length of the input vector or list
15-
out <- length(x.var)
16-
17-
# return output length
18-
return(out)
19-
14+
x.val <- .loadServersideObject(x)
15+
.checkClass(obj = x.val, obj_name = x, permitted_classes = c("character", "factor", "integer", "logical", "numeric", "list", "data.frame"))
16+
list(length = length(x.val), class = class(x.val))
2017
}
2118
#AGGREGATE FUNCTION
2219
# lengthDS

R/numNaDS.R

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
#'
1+
#'
22
#' @title Counts the number of missing values
3-
#' @description this function just counts the number of missing entries
4-
#' in a vector.
5-
#' @param xvect a vector
6-
#' @return an integer, the number of missing values
3+
#' @description this function just counts the number of missing entries
4+
#' in a vector.
5+
#' @param x a character string, the name of a server-side vector
6+
#' @return a list with two elements: \code{numNA} (an integer, the number of
7+
#' missing values) and \code{class} (the class of the input object, for
8+
#' client-side consistency checking)
79
#' @author Gaye, A.
10+
#' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
811
#' @export
912
#'
10-
numNaDS <- function(xvect){
11-
13+
numNaDS <- function(x){
14+
xvect <- .loadServersideObject(x)
1215
out <- length(which(is.na(xvect)))
13-
return (out)
14-
16+
list(numNA = out, class = class(xvect))
1517
}

0 commit comments

Comments
 (0)