Skip to content

Commit d132dde

Browse files
committed
cleaning up as.matrix, as.data.frame methods
1 parent a56dd06 commit d132dde

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ S3method(adjMat,lvm)
7979
S3method(adjMat,lvmfit)
8080
S3method(ancestors,lvm)
8181
S3method(ancestors,lvmfit)
82-
S3method(as.data.frame,sim)
8382
S3method(as.matrix,sim)
8483
S3method(as.vector,sim)
8584
S3method(baptize,lvm)

R/sim.default.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,15 @@ as.vector.sim <- function(x, mode="any") {
176176
}
177177

178178
##' @export
179-
as.data.frame.sim <- function(x, ...) {
180-
class(x) <- "data.frame"
179+
as.matrix.sim <- function(x, ...) {
180+
if (inherits(x, "data.frame")) {
181+
return(as.matrix(as.data.frame(x)))
182+
}
183+
class(x) <- "matrix"
181184
attr(x, "call") <- NULL
182185
attr(x, "f") <- NULL
183186
attr(x, "time") <- NULL
184-
return(x)
185-
}
186-
187-
##' @export
188-
as.matrix.sim <- function(x, ...) {
189-
as.data.frame(x) |> as.matrix()
187+
x
190188
}
191189

192190
##' @export

tests/testthat/test-sim.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ test_that("Missing", {
2626
testthat::expect_equal(sum(d$r),sum(!is.na(d$y0)))
2727

2828
g <- glm(r~x,data=d,family=binomial)
29-
testthat::expect_true(all.equal(coef(g),c(0,1),tolerance=0.2,check.attributes=FALSE))
29+
testthat::expect_true(all.equal(coef(g), c(0, 1),
30+
tolerance = 0.2,
31+
check.attributes = FALSE
32+
))
3033
})
3134

3235

@@ -52,7 +55,10 @@ test_that("sim.default I", {
5255
val <- sim(val,R=2,b0=1,n=10,type=0) ## append results
5356
testthat::expect_true(nrow(val)==4)
5457

55-
s1 <- summary(val,estimate=c(1,1),confint=c(3,4,6,7),true=c(1,1),names=c("Model","Sandwich"))
58+
s1 <- summary(val,
59+
estimate = c(1, 1), confint = c(3, 4, 6, 7),
60+
true = c(1, 1), names = c("Model", "Sandwich")
61+
)
5662
testthat::expect_true(length(grep("Coverage",rownames(s1)))>0)
5763
testthat::expect_equivalent(colnames(s1),c("Model","Sandwich"))
5864

0 commit comments

Comments
 (0)