Skip to content

Commit

Permalink
cleaning up as.matrix, as.data.frame methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kkholst committed Feb 3, 2024
1 parent a56dd06 commit d132dde
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ S3method(adjMat,lvm)
S3method(adjMat,lvmfit)
S3method(ancestors,lvm)
S3method(ancestors,lvmfit)
S3method(as.data.frame,sim)
S3method(as.matrix,sim)
S3method(as.vector,sim)
S3method(baptize,lvm)
Expand Down
14 changes: 6 additions & 8 deletions R/sim.default.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,15 @@ as.vector.sim <- function(x, mode="any") {
}

##' @export
as.data.frame.sim <- function(x, ...) {
class(x) <- "data.frame"
as.matrix.sim <- function(x, ...) {
if (inherits(x, "data.frame")) {
return(as.matrix(as.data.frame(x)))
}
class(x) <- "matrix"
attr(x, "call") <- NULL
attr(x, "f") <- NULL
attr(x, "time") <- NULL
return(x)
}

##' @export
as.matrix.sim <- function(x, ...) {
as.data.frame(x) |> as.matrix()
x
}

##' @export
Expand Down
10 changes: 8 additions & 2 deletions tests/testthat/test-sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ test_that("Missing", {
testthat::expect_equal(sum(d$r),sum(!is.na(d$y0)))

g <- glm(r~x,data=d,family=binomial)
testthat::expect_true(all.equal(coef(g),c(0,1),tolerance=0.2,check.attributes=FALSE))
testthat::expect_true(all.equal(coef(g), c(0, 1),
tolerance = 0.2,
check.attributes = FALSE
))
})


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

s1 <- summary(val,estimate=c(1,1),confint=c(3,4,6,7),true=c(1,1),names=c("Model","Sandwich"))
s1 <- summary(val,
estimate = c(1, 1), confint = c(3, 4, 6, 7),
true = c(1, 1), names = c("Model", "Sandwich")
)
testthat::expect_true(length(grep("Coverage",rownames(s1)))>0)
testthat::expect_equivalent(colnames(s1),c("Model","Sandwich"))

Expand Down

0 comments on commit d132dde

Please sign in to comment.