Skip to content

Commit 0c71f4d

Browse files
authored
Merge pull request #36 from datashield/v6.4.0-dev
V6.4.0 dev
2 parents ce6c28e + 5224c75 commit 0c71f4d

5 files changed

Lines changed: 115 additions & 16 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export(BooleDS)
44
export(absDS)
55
export(asCharacterDS)
6+
export(asDataFrameDS)
67
export(asDataMatrixDS)
78
export(asFactorDS1)
89
export(asFactorDS2)

R/asDataFrameDS.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#' @title asDataFrameDS a serverside assign function called by ds.asDataFrame
2+
#' @description Coerces an R object into a matrix maintaining original
3+
#' class for all columns in data.frames.
4+
#' @details This assign function is based on the native R function \code{data.frame}
5+
#' @param x.name the name of the input object to be coerced to class
6+
#' data.frame. Must be specified in inverted commas. But this argument is
7+
#' usually specified directly by <x.name> argument of the clientside function
8+
#' \code{ds.asDataFrame}
9+
#' @return the object specified by the <newobj> argument (or its default name
10+
#' "asdataframe.newobj") which is written to the serverside. For further
11+
#' details see help on the clientside function \code{ds.asDataMatrix}
12+
#' @author Tim Cadman
13+
#' @export
14+
asDataFrameDS <- function (x.name){
15+
16+
if(is.character(x.name)){
17+
x<-eval(parse(text=x.name), envir = parent.frame())
18+
19+
}else{
20+
studysideMessage<-"ERROR: x.name must be specified as a character string"
21+
stop(studysideMessage, call. = FALSE)
22+
}
23+
24+
output <- data.frame(x)
25+
26+
return(output)
27+
}
28+
# ASSIGN FUNCTION
29+
# asDataFrameDS

R/asDataMatrixDS.R

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
#'
2-
#' @title asDataMatrixDS a serverside assign function called by ds.asDataMatrix
1+
#' @title asDataFrameDS a serverside assign function called by ds.asDataFrame
32
#' @description Coerces an R object into a matrix maintaining original
43
#' class for all columns in data.frames.
5-
#' @details This assign function is based on the native R function \code{data.matrix}
6-
#' If applied to a data.frame, the native R function \code{as.matrix}
7-
#' coverts all columns into character class. In contrast, if applied to
8-
#' a data.frame the native R function \code{data.matrix} converts
9-
#' the data.frame to a matrix but maintains all data columns in their
10-
#' original class
4+
#' @details This assign function is based on the native R function \code{data.frame}
115
#' @param x.name the name of the input object to be coerced to class
12-
#' data.matrix. Must be specified in inverted commas. But this argument is
6+
#' data.frame. Must be specified in inverted commas. But this argument is
137
#' usually specified directly by <x.name> argument of the clientside function
14-
#' \code{ds.asDataMatrix}
8+
#' \code{ds.asDataFrame}
159
#' @return the object specified by the <newobj> argument (or its default name
16-
#' "asdatamatrix.newobj") which is written to the serverside. For further
10+
#' "asdataframe.newobj") which is written to the serverside. For further
1711
#' details see help on the clientside function \code{ds.asDataMatrix}
18-
#' @author Paul Burton for DataSHIELD Development Team
12+
#' @author Tim Cadman
1913
#' @export
20-
#'
21-
asDataMatrixDS <- function (x.name){
14+
asDataFrameDS <- function (x.name){
2215

2316
if(is.character(x.name)){
2417
x <- eval(parse(text=x.name), envir = parent.frame())
@@ -28,9 +21,9 @@ if(is.character(x.name)){
2821
stop(studysideMessage, call. = FALSE)
2922
}
3023

31-
output <- data.matrix(x)
24+
output <- data.frame(x)
3225

3326
return(output)
3427
}
3528
# ASSIGN FUNCTION
36-
# asDataMatrixDS
29+
# asDataFrameDS

man/asDataFrameDS.Rd

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#-------------------------------------------------------------------------------
2+
# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved.
3+
#
4+
# This program and the accompanying materials
5+
# are made available under the terms of the GNU Public License v3.0.
6+
#
7+
# You should have received a copy of the GNU General Public License
8+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
9+
#-------------------------------------------------------------------------------
10+
11+
#
12+
# Set up
13+
#
14+
15+
context("asDataFrameDS::smk::setup")
16+
17+
#
18+
# Tests
19+
#
20+
21+
context("asDataFrameDS::smk::simple")
22+
test_that("simple asDataFrameDS", {
23+
input <- tibble(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0))
24+
25+
res <- asDataFrameDS("input")
26+
27+
res.class <- class(res)
28+
expect_length(res.class, 1)
29+
expect_true("data.frame" %in% res.class)
30+
expect_equal(
31+
dim(res), c(5, 2)
32+
)
33+
34+
expect_equal(res$v1, 0:4)
35+
expect_equal(res$v2, 4:0)
36+
res.colnames <- colnames(res)
37+
expect_length(res.colnames, 2)
38+
expect_equal(res.colnames[1], "v1")
39+
expect_equal(res.colnames[2], "v2")
40+
})
41+
42+
#
43+
# Done
44+
#
45+
46+
context("asDataMatrixDS::smk::shutdown")
47+
context("asDataMatrixDS::smk::done")

0 commit comments

Comments
 (0)