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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:28:14+00:00 2026-05-25T10:28:14+00:00

I am developing a package for R and I would like to set some

  • 0

I am developing a package for R and I would like to set some package-wide defaults with the ability to modify them later. I know this sounds like global variables and thus evil, but I need this to control profiling and debugging and to set the backend (the package can use a variety of external program to do its thing and I call them backends).

All these three settings should change at the same time for all the functions in a call stack. For example, if I call mypackage::function1(profiling = T) and function1 calls mypackage::function2 and mypackage::function3 I would like profiling to be on for those too as far as that call is concerned. One solution could be to do
mypackage::turn.on.profiling() and have all the function refer to some package variable, but it requires trickery with locked environments and stuff like that.

Another could be dynamic scoping, simulated though the sys.frame family of functions (that is, once profiling is on, it’s on for anything below that point on the stack). Don’t tell me that profiling in R doesn’t work like that because this is a different type of profiling, built on top of the existing one but different.

I have no doubt that I can hack it one way or another, but I was wondering if there is a canonical solution or at least some precedent in CRAN for something of this sort so that I won’t reinvent the wheel.

  • 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-25T10:28:15+00:00Added an answer on May 25, 2026 at 10:28 am

    Another simple way is to put the parameters in an environment object in your package and have your turn.on.profiling-like function modify it.

    # Don't export this 
    .profileOptions <- new.env(parent=emptyenv())
    .profileOptions$enabled <- FALSE
    
    # export this one
    profilingEnabled <- function(flag = NA) {
        oldFlag <- .profileOptions$enabled
        if (!is.na(flag)) {
           .profileOptions$enabled = flag
        }
        oldFlag
    }
    
    # then use it
    profilingEnabled() # returns TRUE or FALSE
    profilingEnabled(TRUE) # enables profiling, returns previous state
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a Python 2.6 package in which I would like to fetch a
I'm developing some cross platform software targeting Mono under Visual Studio and would like
I have 10 apps I'm developing and would like to have them all on
I am developing some convenience wrappers around another software package that defines a bash
I'm developing a qtwebkit based editor on linux using pyqt. I would like to
I would like to learn to use Oracle some, just for the sake of
I am developing a Python package for dealing with some scientific data. There are
Question: I am testing functions in a package that I am developing and would
I'm developing a Visual Studio Integration Package. When I try to run the Unit
Developing websites are time-consuming. To improve productivity, I would code a prototype to show

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.