/
asDataMatrixDS.R
34 lines (30 loc) · 1.38 KB
/
asDataMatrixDS.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#' @title asDataMatrixDS a serverside assign function called by ds.asDataMatrix
#' @description Coerces an R object into a matrix maintaining original
#' class for all columns in data.frames.
#' @details This assign function is based on the native R function {data.matrix}
#' If applied to a data.frame, the native R function {as.matrix}
#' coverts all columns into character class. In contrast, if applied to
#' a data.frame the native R function {data.matrix} converts
#' the data.frame to a matrix but maintains all data columns in their
#' original class
#' @param x.name the name of the input object to be coerced to class
#' data.matrix. Must be specified in inverted commas. But this argument is
#' usually specified directly by <x.name> argument of the clientside function
#' {ds.asDataMatrix}
#' @return the object specified by the <newobj> argument (or its default name
#' <x.name>.mat) which is written to the serverside. For further
#' details see help on the clientside function {ds.asDataMatrix}
#' @author Paul Burton for DataSHIELD Development Team
#' @export
asDataMatrixDS <- function (x.name){
if(is.character(x.name)){
x<-eval(parse(text=x.name), envir = parent.frame())
}else{
studysideMessage<-"ERROR: x.name must be specified as a character string"
return(list(studysideMessage=studysideMessage))
}
output <- data.matrix(x)
return(output)
}
#ASSIGN FUNCTION
# asDataMatrixDS