Questions tagged [r-environment]
57 questions
1
vote
1 answer
Inside an R function, how do I access the calling environment?
foo <- function() {
# how to know what environment_of_caller is
}
caller <- function() {
# environment_of_caller
foo()
}
A function that I'm writing needs to the know the environment of its caller. Can that be done without passing the…

Bear Bile Farming is Torture
- 4,317
- 4
- 27
- 61
1
vote
0 answers
Detect methods in other environments in R -- for testing in testthat
Is it possible to allow "UseMethod" to see class functions defined in other environments? See the below code for an example. I would like the h.logical to be detected too such that h(TRUE) would return "logical".
h <- function(x) {
…

Mark
- 173
- 4
1
vote
2 answers
Why are objects masked after running library(renv) in R?
I'm following this steps, like in this workflow here:
renv::init()
working as usual and installing new packages
renv::snapshot()
The problem I'm facing is while running library(renv), many functions are been masked, like load, so I have to re-mask…

lo labs
- 89
- 13
1
vote
1 answer
How load a dynamic data frame in Global R environment?
I am working in the development of an app for decision trees using shiny, and java script.
I have a structure of a dynamic tree, where the user can create new branchess and nodes and when the user finishes the construction of his tree, he can press…

coding
- 917
- 2
- 12
- 25
1
vote
2 answers
Change default directory opened by RStudio when I "File/Open Project..."
When I click on "File/Open Project..." RStudio opens my home directory at "~", but I would like to open the directory at "~/Documents/coding/" where I store all my Rprojects. How can I change the default directory that RStudio opens when it opens…

Joe
- 3,217
- 3
- 21
- 37
1
vote
1 answer
What is the best way to create the user library directory set in .Renviron?
I'm trying to find the best way to setup R for my team. Because our institution has the user home directory on a network share, the R user library is defaulted to this network share.
After some research, I found that setting R_LIBS_USER in the…

Jelger van Zaane
- 69
- 13
1
vote
1 answer
Reading data into R
I am trying to read data from the msigdb database into my R environment, but I am having trouble reading it into the format that I would like. Right now when I read the data in it is read as the type "integer", I want it read in as the type…

Rohan Singhal
- 33
- 3
1
vote
1 answer
How to check if an environment is a package namespace
I am looking for a way to detect if an environment is a package namespace. Desired behavior:
is.namespace(environment(data.frame))
## [1] TRUE
is.namespace(environment(ggplot2::ggplot))
## [1] TRUE
is.namespace(globalenv())
## [1]…

landau
- 5,636
- 1
- 22
- 50
1
vote
1 answer
Define environment only accessible from a given function
I have the following function designed to print a progress bar outside of loops, it works well but creates an environment object in the global environment.
I'm not so comfortable with environments but I think I could set up this environment to be…

moodymudskipper
- 46,417
- 11
- 121
- 167
0
votes
0 answers
Using GAMLSS predictions within a wrapper function
I'm trying to write functions that wrap basic gamlss modeling (because I'm preparing a higher-level, application-specific package). But I've run into issues wrapping predict.
The example from the predict.gamlss documentation works…

Krisrs1128
- 311
- 4
- 8
0
votes
1 answer
Using base load in an active renvironment
I am working on an R markdown notebook in an active renv in my R project directory. Before I had activated the environment, I could use the load function from base R without a problem. But since activating the environment, I get errors when I use…

dapple-putt-poultry
- 103
- 6
0
votes
0 answers
MICE package in R 10x slower with new R
I recently updated my R (from 4.0 to 4.2) and now mice() runs much slower on the same data. Has this happened to anyone else ?
Maybe my .Renviron got reset and something like the R_MAX_VSIZE needs to change ? It doesn't seem to help mice().
Thank…

Shira
- 119
- 5
0
votes
1 answer
RShiny adding a module within a loop, based on user input
I want to make an RShiny app where the user can select a folder, and then add a navbarMenu containing as many tabPanels as there are files in the selected folder. The tabPanels are made with a module. Here is an app with a button that adds just one…

Quillox
- 11
- 2
0
votes
1 answer
I can't install the sf package when I use the renv package in a project
I started a new project in Rstudio and selected the option to use renv. The first thing I did was type the command install.packages('sf') and R returned the message below. How to proceed?
> install.packages('sf')
Error: package 'sf' is not…

Igor
- 145
- 8
0
votes
1 answer
inheritance in rlang's env_get doesn't seem to see bindings in the grandparent environment
In the following example, I try to get an element from a grandparent environment using env_get. The first bit works as expected.
library(rlang)
e1 <- env(a = 'a')
# works as expected
f <- function() {
env_get(
env = caller_env(),
nm =…

crf
- 1,810
- 3
- 15
- 23