Questions tagged [r-environment]

57 questions
2
votes
1 answer

Changing a package function's environment in R

I have a situation where I have a function whose environment I want to change. This function is in a local custom R package. Here's my setup. I have an R package project called testpkg with one function in /R called do_stuff.R: #' A function that…
Will Hipson
  • 366
  • 2
  • 9
2
votes
0 answers

Recover previous value of R environment variable "PATH"

I have R 4.1.2 with RStudio 2021.09.2 on Windows 10 Enterprise on a University network. When I installed Rtools 4.0, I followed forum advice for putting Rtools on the path, including the following console…
batcatcher
  • 33
  • 3
2
votes
1 answer

Using renv: where should renv itself be installed?

I am getting started with collaborating with team members on R projects using renv. While I can (mostly) get it to work, I am a bit confused about whether and where to install renv itself. According to the documented workflow I basically need renv…
gira
  • 175
  • 6
2
votes
1 answer

renv:restore() always fails in windows

Whenever I want to recreate a project on my windows machine using renv:restore() it always fails installing packages. I always get the same error (although the packages may change): Retrieving…
ccamara
  • 1,141
  • 1
  • 12
  • 32
2
votes
2 answers

Why doesn't R look up for the specified object in the provided envrionment parents tree?

Configuration: OS : Windows 10 (64 bits) R version: 3.6.3 I'm learning R and currently I'm reading about the environments in R. I was doing some practice and I came up with an example that I created myself, yet it seems that I'm still unable to…
user17911
  • 1,073
  • 1
  • 8
  • 18
2
votes
1 answer

R: Evaluating a script in an environment

I would like to load a library function within a script evaluated in a specified environment. Example: ## foo.R ## ----- ## blah blah library(extrafont) loadfonts() Assuming for convenience the evaluation environment is the base…
antonio
  • 10,629
  • 13
  • 68
  • 136
2
votes
2 answers

R passing RSelenium driver environment as function argument

i'm probably not seeing something obvious, anyway i'd like to create functions to automatically extract text from an url already handled by a remote driver. I'd like to pass as a function arguments the xpath expression and the environment into which…
1
vote
1 answer

"unpack" contents of an R environment object to current working environment

I want to achieve an effect similar to saving and loading .RData files like the following code, but without writing anything out to a file, and using environments instead. a <- 1 c <- 3 save('a', 'c', file="file.RData") a <- 'foo' b <-…
goweon
  • 1,111
  • 10
  • 19
1
vote
0 answers

Renv and Java: "Error in rJava::.jinit() : Unable to create a Java class loader"

I have a script that works perfectly when I'm not using Renv. However, when running it in a project with Renv enabled, the last command line returns the following message: > r5r_core <- setup_r5(data_path = data_path, verbose = FALSE) Error in…
Igor
  • 145
  • 8
1
vote
1 answer

Generate and render rmd from within shinyapp

I wrote a shiny app that includes generating an rmd file and then rendering it into html report. As shown in the simple example below, there is a variable created inside the server function of shinyapp, then the created rmd file should have access…
Bahi8482
  • 489
  • 5
  • 15
1
vote
2 answers

Set a script environement that is different from the global environment

I have a number of loosely related data analysis scripts in R. Some of these scripts have code that removes all variables from the global environment in order to wipe sensitive information after running. Other scripts have variable names that are…
kamiks
  • 184
  • 7
1
vote
4 answers

How to run an arbitrary expression in an environment, storing all results in the environment?

In R, running the expression x <- 1 defines a variable x in the global environment with the value 1. Doing the same within a function defines the variable within the function's environment instead. Using rlang::with_env, we can also do the same…
Wasabi
  • 2,879
  • 3
  • 26
  • 48
1
vote
1 answer

abline() is not working with weighted.hist()

So I used the plotrix library to plot a histogram using some weights , the histogram shows up as expected but when I tried a plot the mean as a vertical line it won't show up at all Here's a snippet of my…
AmirWG
  • 251
  • 1
  • 2
  • 10
1
vote
2 answers

R glue with limited set of functions allowed in pattern?

I am using glue() to format strings. Ideally I would like to give the user the option to provide his own, potentially complex formatting patterns. These will usually be distributed as part of a yaml config file, which also contains many other…
meow
  • 925
  • 7
  • 22
1
vote
2 answers

Is there something like print method for environment in R?

I have created a simple environment in R with two simple function, AnEnv <- new.env() AnEnv$mod <- function(a, b) a%%b AnEnv$pwr <- function(a, b) a^b Whenever I type AnEnv in R-console, it returns something like . Is…
TheRimalaya
  • 4,232
  • 2
  • 31
  • 37