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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:05:37+00:00 2026-05-26T18:05:37+00:00

Is it possible to source methods to an environment other than .GlobalEnv ? I’m

  • 0

Is it possible to source methods to an environment other than .GlobalEnv?

I’m slowly getting a bit frustrated over R’s masking mechanism (I’ll probably be back with an own question in this respect, but if you’re interested, for the moment just try using packages RMySQL and RSQLite in the same process and loading them in this order; makes my RMySQL stuff crash) and would very very much like to switch to consistently using <namespace>::foo() instead of just foo() throughout all of my scripts.

Yet, using <namespace>::foo() is less efficient than using a “local copy” (e.g. namespace..foo <- <namespace>::foo(); I can provide examples for those interested, but it’s very easy to test for yourself).

Making local copies works a treat for other packages I’m loading since (most of them) do have a namespace, but before my own code turns “package” it does not.

So I though “let’s just source my stuff to NS <- newenv(parent=emptyenv()) and then apply the same routine as for the other packages”. But R won’t let me:

setGeneric(
    name="fooBar",
    signature=c("src"),
    def=function(src, ...){
        standardGeneric("fooBar")    
    }
)
setMethod(
    f="fooBar",
    signature=signature(src="character"),
    definition=function(src, ...){
        cat(src, sep="\n")        
    }
)
# These would go into: 
"Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/gnrc.R"
"Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/mthd.R"

# This works:
source("Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/gnrc.R")
source("Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/mthd.R")

# This does not:
NS <- new.env(parent=emptyenv())
source("Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/gnrc.R", local=NS)
source("Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/mthd.R", local=NS)

eval(parse(file="Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/gnrc.R"), envir=NS)
eval(parse(file="Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/mthd.R"), envir=NS)

Errors:

> source("Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/gnrc.R", local=NS)
Error in eval.with.vis(expr, envir, enclos) : 
  could not find function "setGeneric"
> source("Q:/usr/wsp/3.6.2/32bit/root/_SCRATCH/mthd.R", local=NS)
Error in eval.with.vis(expr, envir, enclos) : 
  could not find function "setMethod"

Any idea what I might be doing wrong?

  • 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-05-26T18:05:37+00:00Added an answer on May 26, 2026 at 6:05 pm

    OMG! I’m sorry guys, this is somewhat embarrassing:

    I’ve switched to using new.env(parent=emptyenv()) consistently in order to prevent some memory ballooning when caching environments and got so used to it that I forgot that it does make sense to have different parent envirs at time 😉

    In this case NS <- new.env() will do the trick.

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

Sidebar

Related Questions

I've never used source control before (always used renaming files and other methods), so
Is it possible to source a file without printing all the charts etc (already
I'm looking for a LHarc de/compressing library, with source if possible.
Possible duplicate What is the best open source example of a lightweight Windows Application?
Is that possible to switch an Open Source Project license from GPL to LGPL
Is it possible to verify which source safe project is bound to my vs.net
Is it possible to browse the source code of OpenJDK online, just like I
Is it possible to get the current source line number in Perl? The equivalent
Is it possible for a python script to open its own source file and
Is it possible to generate a list of all source members within an iSeries

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.