s4

get predictor data types from H2OModel

ぃ、小莉子 提交于 2019-12-11 17:51:12
问题 I know that I can access the predictor names of an H2OModel via the @parameters slot, but can I access the predictor data types ? I'm trying to generate an input schema for my h2OModel , and right now I have to cross-reference the training_frame and get data types from there. Obviously, this would be a problem if my training_frame was no longer in memory. Here's my current approach: getInputSchema <- function(model){ require(jsonlite) require(h2o) training_frame <- h2o.getFrame(model

do.call error “second argument must be a list” with S4Vectors when the code is in a library

我的梦境 提交于 2019-12-11 07:12:43
问题 This is a question raised in the context of this other one: Extract and paste together multiple columns of a data frame like object using a vector of column names I received an answer based on the usage of do.call which happens to not work when the code is part of a library, but worked well when implemented as part of the main script. Here is my attempt at making a simplified example: File example.do.call.R : library(S4Vectors) library(test.package) data <- DataFrame(A=letters[1:6], B=LETTERS

How to extract value from one S4 class

筅森魡賤 提交于 2019-12-11 04:27:25
问题 Probably a naive question: >library("coin") > b <-independence_test(c(23,56,18) ~ c(1,3,2),teststat = "quad") > b Asymptotic General Independence Test data: c(23, 56, 18) by c(1, 3, 2) chi-squared = 1.2772, df = 1, p-value = 0.2584 I tried to find a place to extract this pValue (0.2584) but failed. Please help. Thanks in advance. 回答1: It was hard to guess but I always look on the S4 class structure with str function and then I wound out that there is test statictic and pvalue function

How do I see existing classes

微笑、不失礼 提交于 2019-12-11 03:32:19
问题 I have used the setClass function to define several new classes. But these classes don't appear in my Rstudio environment. How do I see all the classes that exist? Here is an example: setClass("geckoNss", representation(absolute = "character", item = "list")) The class now exists somewhere, as we can do > getClass("geckoNss") Class "geckoNss" [in ".GlobalEnv"] Slots: Name: absolute item Class: character list and make objects of that class: > new("geckoNss") An object of class "geckoNss" Slot

R S4 roxygen2 documentation

巧了我就是萌 提交于 2019-12-11 02:04:28
问题 I'm using roxygen2 for documentation in S4 and for some reason the usage section is not showing up. I made a simple example to show my confusion: #' Title #' #' @param x Temp #' #' @return Nothing of interest. #' #' @export #' @docType methods #' @rdname A-methods setGeneric("A", function(x, ...){ cat("test\n") standardGeneric("A") }) #' @rdname A-methods #' @aliases A,ANY,ANY-method setMethod("A", "ANY", function(x, ...){ cat(class(x)) }) #END# 回答1: IMHO that is a common problem. You could

Lazy evaluation for S4 method arguments

你。 提交于 2019-12-10 17:29:14
问题 I'm implementing an S4 class that contains a data.table , and attempting to implement [ subsetting of the object (as described here) such that it also subsets the data.table . For example (defining just i subsetting): library(data.table) .SuperDataTable <- setClass("SuperDataTable", representation(dt="data.table")) setMethod("[", c("SuperDataTable", "ANY", "missing", "ANY"), function(x, i, j, ..., drop=TRUE) { initialize(x, dt=x@dt[i]) }) d = data.table(a=1:4, b=rep(c("x", "y"), each=2)) s =

R: Applying terms.formula on an S4 object inheriting data.frame

六眼飞鱼酱① 提交于 2019-12-10 17:12:52
问题 I'm trying to create a new class that inherits from data frame: > setClass('new.frame', representation(colour='character'), contains = 'data.frame') This is an instance of that class, for testing: > test_data = data.frame(cbind(runif(5), runif(5))) > names(test_data) = c('X', 'Y') > test_frame = new('new.frame', test_data, colour='red') Just to make sure it looks all right... > data.frame Object of class "new.frame" X Y 1 0.8766306 0.4741213 2 0.1221508 0.5117665 3 0.4838761 0.4973627 4 0

`as.matrix` and `as.data.frame` S3 methods vs. S4 methods

社会主义新天地 提交于 2019-12-10 13:57:07
问题 I noticed that defining as.matrix or as.data.frame as S3 methods for an S4 class makes e.g. lm (formula, objS4) and prcomp (object) work out of the box. This doesn't work if they are defined as S4 methods. Why does it matter whether the methods are defined as S3 or S4 method? Example for as.data.frame : setClass ("exampleclass", representation (x = "data.frame")) object <- new ("exampleclass", x = iris) setMethod ("as.data.frame", signature="exampleclass", definition= function (x, ...) x@x )

Multiple dispatch for `subset` methods in R

大城市里の小女人 提交于 2019-12-10 11:33:32
问题 I am developing a package and want to write two subset methods for objects of a custom class, myclass , with dispatch on two arguments, first one being the object to subset, of class myclass , and the second being either logical of character vector, like so: setMethod( f = "subset", signature = c(x = "myclass", subset = "logical"), definition = function(x, subset){ # function body } ) setMethod( f = "subset", signature = c(x = "myclass", subset = "character"), definition = function(x, subset)

Converting package using S3 to S4 classes, is there going to be performance drop?

和自甴很熟 提交于 2019-12-09 08:56:10
问题 I have an R package which currently uses S3 class system, with two different classes and several methods for generic S3 functions like plot , logLik and update (for model formula updating). As my code has become more complex with all the validity checking and if/else structures due to to the fact that there's no inheritance or dispatching based on two arguments in S3 , I have started to think of converting my package to S4 . But then I started to read about the advantages and and