One of the methods of object oriented programming in the R language.
Questions tagged [r-s4]
647 questions
0
votes
0 answers
S4 Programming Error in .local(.Object...)
I have made all my functions into generics and methods on their respective classes.
But now what worked as functions no longer works.
Class bond.id has no generic or methods.
It only holds variables that are passed to a, b, and c, each of these all…

no name
- 245
- 2
- 14
0
votes
1 answer
Manipulating S4 Classes
Example of the problem - class.a has slots 1, 2, 3
and inherits from class c (4, and 5).
The slots in class (1, 2, 3) are passed to function.b as variables.
the output of function b is as class.c. So now I have the following.
class.a
…

no name
- 245
- 2
- 14
0
votes
1 answer
Call default constructor of a S4 by class name
Are there more ways to call a function by name like I do below via do.call?
setClass(Class = "MyClass",
representation = representation(name = "character",
type = "character"
)
)
MyClass <-…

Klaus
- 1,946
- 3
- 19
- 34
0
votes
1 answer
Declare a arbitrary data type
Is it possible to declare a variable btw. representation like "obj" of a arbitrary type, that means an ancestor, where all data types derived from? So that I can appropriate each type to representation type? Should I put this flexible parameter into…

Klaus
- 1,946
- 3
- 19
- 34
0
votes
0 answers
Interdependency between 2 files in an R package
I am writing a package that contains two R files, file1.R and file2.R. The first file contains several function and S4 object definitions that the second file uses. I tried adding source("file1.R") to the top of file2.R but when I installed the…

Jon Claus
- 2,862
- 4
- 22
- 33
0
votes
1 answer
Using S4 object output in source packages
I have lately tried to organize all my functions in packages to avoid having hundreds of lines of code on top of each script. I have written a number of functions that I use after running a set of LME4 multilevel models. These functions are designed…

Raphael
- 1,143
- 1
- 11
- 16
0
votes
0 answers
Using generic function
I dont know how to deal with the name of a generic function, e.g.
setClass(Class = "ABC",
representation = representation(a="numeric")
)
ABC<-function(a=1){new("ABC",a=a)}
setGeneric("geta", function(object)…

Klaus
- 1,946
- 3
- 19
- 34
0
votes
1 answer
S4 object in R cannot be passed to Fortran
I use the bdiag function in the Matrix package in R to generate diagonal matrix, and then I pass the resultant matrix (called mat) into a self-written function but R fails to execute due to the following error:
Error: invalid mode (S4) to pass to…

alittleboy
- 10,616
- 23
- 67
- 107
0
votes
1 answer
Storing a content in to a desired object
I have a vector like this :
vec1 <- c("x1","x2","x3","x4")
I have another vector like this :
vec2 <- c("X1.RData","X2.RData","X3.RData","X4.RData")
What I am trying to do here is to load the RData files and then save them back with the same file…

user1021713
- 2,133
- 8
- 27
- 40
0
votes
2 answers
S4 class for chunked data in R- inherited numeric methods won’t work
I want to create an S4 class in R that will allow me to access large datasets (in chunks) from the cloud (similar to the goals of the ff package). Right now I'm working with a toy example called "range.vec" (I don't want to deal with internet access…

Eli Sander
- 1,228
- 1
- 13
- 29
0
votes
3 answers
Slots of typ formula
I am trying to use a slot of type formula. But formula isn't a basic datatype. What can I do to create a slot to store objects like formula. Or is it intentional to prohibit storing general S3 objects as slots? If it's intentional to use slots of…

Klaus
- 1,946
- 3
- 19
- 34
-1
votes
1 answer
Printing nested cars S4 objects
I am new to R and trying to figure out how to print/save a class S4 object that is nested into a list.
This is the structure of the list. The list contains many of these mm9 fasta sequence subsets like the one in the figure. They contain different…

Luca
- 1
-1
votes
1 answer
Use do.call to get information out of a list of RC/S4 objects
I have a defined reference class and a list:
RCclass<-setRefClass("RCclass",field=list(info="character"))
A<-RCclass$new(info="a")
B<-RCclass$new(info="b")
testList<-list(A,B)
do.call(function(x){paste0(x$info)},testList)
The do.call function…

chl111
- 468
- 3
- 14
-1
votes
1 answer
S4 class from readr read_csv output
I wanted to create an S4 class which represents the data from a read_csv function call (readr package)
library(readr)
library(magrittr)
#data <- read_csv("random.csv")
data <- structure(list(id = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
…

andrnev
- 410
- 2
- 12
-1
votes
1 answer
Does R support collections in S4?
I have created an S4 class ("card") that resembles a record with several fields. Now I want to define a collection class ("cat") to hold many "card" objects. The cat class will include methods for searching, editing, and adding cards.
Here is a…

AltShift
- 336
- 3
- 18