Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:08:32+00:00 2026-06-09T20:08:32+00:00

I want to create an S4 class in R that will allow me to

  • 0

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 yet), which stores a sequence of numbers like so:

setClass("range.vec",
representation(start = "numeric", #beginning num in sequence
end = "numeric",                  #last num in sequence
step = "numeric",                 #step size
chunk = "numeric",                #cache a chunk here to save memory
chunkpos = "numeric"),            #where does the chunk start in the overall vec
contains="numeric"                #inherits methods from numeric
)

I want this class to inherit the methods from “numeric”, but I want it to use these methods on the whole vector, not just the chunk that I’m storing. For example, I don’t want to define my own method for ‘mean’, but I want ‘mean’ to get the mean of the whole vector by accessing it chunk by chunk, using length(), ‘[‘, ‘[[‘, and el() functions that I’ve defined. I’ve also defined a chunking function:

setGeneric("set.chunk", function(x,...) standardGeneric("set.chunk"))
setMethod("set.chunk",  signature(x = "range.vec"),
    function (x, chunksize=100, chunkpos=1) {
    #This function extracts a chunk of data from the range.vec object.
    begin <- x@start + (chunkpos - 1)*x@step
    end <- x@start + (chunkpos + chunksize - 2)*x@step
    data <- seq(begin, end, x@step) #calculate values in data chunk

    #get rid of out-of-bounds values
    data[data > x@end] <- NA

    x@chunk <- data
    x@chunkpos <- chunkpos
    return(x)
}})

When I try to call a method like ‘mean’, the function inherits correctly, and accesses my length function, but returns NA because I don’t have any data stored in the .Data slot. Is there a way that I can use the .Data slot to point to my chunking function, or to tell the class to chunk numeric methods without defining every single method myself? I’m trying to avoid coding in C if I can. Any advice would be very helpful!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:08:33+00:00Added an answer on June 9, 2026 at 8:08 pm

    Looks like there isn’t a good way to do this within the class. The only solution I’ve found is to tell the user to calculate to loop through all of the chunks of data from the cloud, and calculate as they go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a class that initializes a timer which will be used
I want to create a Javascript class/object that allow me to have various method:
I want to create a servlet that will allow me to upload image files
I want to create a class that can add methods dynamically and allow multiple
I'm trying to create a class that will allow me to add/multiply/divide objects of
I want to create whois class like that public class DomainInfo { public string
I want to create a wrapper class so that all queries should not be
If I create a class that extends UserControl and want to set a default
I want to create a substr method in C++ in a string class that
I have a signed class library that I want to create assemblies for via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.