Questions tagged [r-s4]

One of the methods of object oriented programming in the R language.

647 questions
0
votes
1 answer

Error while extracting netcdf files into raster

I have many NCDF files in a folder. I try to extract them into raster brick using raster and ncdf4 packages. If I separately extract each NCDF file it works. However, I try to extract all files using for loop then it gives me…
rar
  • 894
  • 1
  • 9
  • 24
0
votes
1 answer

R Instance of S4 object with S3 attribute

I am currently creating a new S4 class which uses a S3 zoo object. I can create a class setOldClass("zoo") setClass("rollingSD", slot = c(rollPeriod = "numeric", tsOutput = "zoo")) This code works fine. Now if I want to create an object as riskSD…
mth_mad
  • 135
  • 1
  • 10
0
votes
1 answer

Creating a class S4 class in R with a Zoo object attribute

I would like to create a new time series class with an attribute being a Zoo object. Unfortunately, the "zoo" class is not recognised. library(zoo) setClass("timeseries", representation(ts = "zoo", name = "character"),) Warning message: undefined…
mth_mad
  • 135
  • 1
  • 10
0
votes
1 answer

Show elements, slots for S4 classes when you press Tab in constructor call

Just for the cake of convenience how to make R to show class's fields when you press Tab in constructor call? Let me show you what I mean - there is a class: cEvent = setClass( "Event", representation( time = "POSIXct" ) ) then when…
stkubr
  • 371
  • 1
  • 5
  • 15
0
votes
1 answer

Automated porting of R library for Renjin

I have some local R libraries that I would like include in my renjin Java application. Some of the libraries are written entirely in R, some libraries have C++ dependencies and some libraries have S4 classes. Ideally, I don't want to maintain two…
Mfswiggs
  • 307
  • 1
  • 6
  • 16
0
votes
0 answers

R S4 Class / Object

I have an S4 class object: class(pred) [1] "prediction" attr(,"package") [1] "ROCR" and pred has following columns slotNames(pred) #[1] "predictions" "labels" "cutoffs" "fp" "tp" "tn" "fn"…
Sourabh
  • 73
  • 1
  • 18
0
votes
1 answer

How to find the default construstor methods for a class

Problems comes from experimenting a package and find using new(Class = 'ddmatrix', Data = X) and ddmatrix(Data = X) yields different results, in which X is a matrix(one can think class ddmatrix is a transformed Class matrix). Document In the…
Bs He
  • 717
  • 1
  • 10
  • 22
0
votes
1 answer

Efficient way of s4 object in R ?

I'm trying to define schools with identifiers and some other parameters and classes in each school with identifiers and some other parameters and students and teacher for each class. I defined S4 objects for each type. i.e. student <- setClass( …
Shin
  • 107
  • 8
0
votes
2 answers

R: extract parameter estmates from object of class 'mle'

I was wondering how one extracts the estimated parameters stored in an R object of class mle-class. Here is an example: x <- matrix(rnorm(300), ncol = 3) x[x > 1] <- 1 require(tmvtnorm) fit1 <- mle.tmvnorm(X = x, lower = rep(-Inf, 3), upper = rep(1,…
user3236841
  • 1,088
  • 1
  • 15
  • 39
0
votes
1 answer

Selecting a subset of a big SpatialPolygonsDataFrame using a masking vector

Can anyone help me understand why this doesn't work how I think it should? I have a 1,000+ element SpatialPolygonsDataFrame object (i.e. from sp) and I'd like to cut it down to a vector of 20 random items from the whole. n <- dim(geo1) # where geo1…
nivek
  • 515
  • 1
  • 7
  • 18
0
votes
1 answer

The correct way to set a function generic and overload it with different arguments within a package

Let's assume that I want to define the function rankMatrix from the Matrix package for my own S4 class objects. Doing this in a running R session seems to be straightforward: library(devtools); library(roxygen2);…
R大卫
  • 150
  • 7
0
votes
0 answers

R no method for coercing S4 class to a vector BioConductor AnnotationDbi package

I have in code a method call: > MYOBJECT PATHID2NAME map for KEGG (object of class "AnnDbBimap") I am running somebody else's function and getting an error >as.list.default(MYOBJECT) : no method for coercing this S4 class to a vector I can see…
Milo Hou
  • 239
  • 2
  • 17
0
votes
0 answers

R custom package - Imported function not found when trying to create NAMESPACE

I'm working on a custom R package, in which I'm using S4 classes and methods. In one of the methods for a custom S4 class in the same file, I'm using the GET() method from the httr package. I tried using roxygen2 to properly set up my NAMESPACE…
jakobus
  • 1
  • 4
0
votes
1 answer

How to import `as<-`?

In developing an R package, how do I import the as() method for an S4 class? More details: I need to convert an adjacency matrix to a graphNEL object (from the graph package). Here is the code for doing so: library("graph") m <- rbind( c(0, 0, 0,…
JohnA
  • 321
  • 2
  • 11
0
votes
0 answers

R - S3 or S4 for functions with single arguments?

My understanding of the two main OOP systems in R is that S3 is very simple but not very rigorous for validity whereas S4 is more rigorous but more complex. Generally, the guidelines I have seen are if your function depends on multiple arguments…
cdeterman
  • 19,630
  • 7
  • 76
  • 100