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 8210739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:10:40+00:00 2026-06-07T10:10:40+00:00

Assgning a value to one field, how can I make the other fields changing.

  • 0

Assgning a value to one field, how can I make the other fields changing.

Consider the following ReferenceClass object:

C<-setRefClass("C", 
      fields=list(a="numeric",b="numeric")
      , methods=list(
      seta = function(x){
      a<<-x
      b<<-x+10
      cat("The change took place!")
      }
      ) # end of the methods list
      ) # end of the class

Now create the instance of the class

c<-C$new() 

This command

c$seta(10)

will result in that c$a is 10 and c$b is 20.

So it actually works, however, I want to achieve this result by the command

c$a<-10

(i.e. after that I want c$b to be equal to 20 as defined in the class in the logic of seta() function)
How can I do it?

  • 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-07T10:10:42+00:00Added an answer on June 7, 2026 at 10:10 am

    I think you are looking for accessor functions, which are described in detail in ?ReferenceClasses. This should work:

    C<-setRefClass("C", 
        fields=list(
            a=function(v) {
                  if (missing(v)) return(x)
                  assign('x',v,.self)                    
                  b<<-v+10
                  cat ('The change took place!')
                }
           ,b="numeric"
        )
        ,methods=list(
            initialize=function(...)  {
                 assign('x',numeric(),.self)
                .self$initFields(...)
            } 
        )
    )
    
    c<-C$new()
    c$a
    # numeric(0)
    c$a<-3
    # The change took place!
    c$b
    # 13
    c$a
    # 3
    

    It does have the side effect that a new value, x is now in the environment c (the class object), but it is ‘hidden’ from the user in the sense that just printing c will not list x as a field.

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

Sidebar

Related Questions

Greetings! When assigning a value to an array as in the following, how could
I need to add the following items to a combo box. Value DisplayText Mpost
I'm getting a strange error when assigning a value to one of my objects.
Using GCC, if you switch on an enum value and one of the enums
When assigning a default default-value to a field (here false to a bool), FxCop
Hi i'm having problems assigning a value to a custom field. i've added multiple
Hi There is one xml in which i am assigning the value of password
I´m trying to copy an Attribute value from one element in the schema to
Possible Duplicate: Unsigned long with negative value Assigning negative numbers to an unsigned int?
I am having trouble over simply assigning a value to a UI Button: //Assume

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.