All Questions
267
questions
2
votes
1
answer
54
views
how to view modified environment in R
In this R question, lexical scoping is used to implement a stateful function. The setter and getter methods for a point "class" work as expected to change the coordinates of the point, a &...
2
votes
1
answer
61
views
Are there any risks to accessing internal functions with :: or :::?
I've been developing a package in R which has a number of functions (some exported, some not) which are used by other functions in the package. Since the package loads and attaches itself, is there ...
1
vote
1
answer
25
views
Scope of identifiers in R formulas/expressions
I'm using as.ggplot from ggplotify to wrap some chord diagrams from the circlize package so I can arrange them nicely using patchwork. However, since as.ggplot takes a formula or expression as an ...
1
vote
2
answers
83
views
How to keep function call attributes consistent in lapply and Map?
I want to attach the function call as an attribute. While using fn() directly works fine, when I run it inside lapply(), it returns X[[i]] instead of the actual name passed to the d= parameter. I ...
0
votes
1
answer
124
views
R Variable scoping issue of parallel calculation (%dofuture%) in a nested function
I have a variable scoping issue when I try to do the parallel calculation using %dofuture% in a nested function.
Here is the error message I get:
Error in eval(quote({ : object 'opt' not found
Here ...
1
vote
2
answers
69
views
Avoid lazyness in ggplot aes(color=variable)
In a for-loop I continue to add geom_... to a plot. I'd like each geom-object to have a separate color and a corresponding entry in the legend.
library(ggplot2)
means <- 1:5
sds <- 1:5
plt <...
0
votes
0
answers
72
views
Scope variables and functions in R
I have the following data:
trials <- data.frame(
full_condition = rep(c("condition1", "condition2", "condition3"), times = 3),
participant_md5 = rep(c("...
3
votes
0
answers
93
views
Setter not found when used inside an R package
First time asking here -I will try to do my best-.
I am writing an analysis package using R for which unfortunately I cannot disclose much. The core object that the package is using to get data and ...
2
votes
1
answer
148
views
Is there a python equivalent to R's `with`?
In R, the with function constructs an environment from some data - this allows you to refer to items in your data as if they are variables, so this:
with(list("a" = 12, "b" = 13), {...
0
votes
0
answers
39
views
forecast subset function is not accessible via :: notation
Consider this MWE and it outputs:
forecast::subset(forecast::woolyrnq, start = 0 , end = 10)
# Error: 'subset' is not an exported object from 'namespace:forecast'
forecast:::subset(forecast::woolyrnq,...
2
votes
2
answers
34
views
R: Back-referencing data frame in `with` expression
Is there a way to back-reference the scope in a with expression in R?
I'm trying to write the following (valid) statement in a more elegant (i.e. non-repetitive) way:
with(subset(mtcars, cyl > 4), {...
2
votes
1
answer
82
views
predict.lme is unable to interpret a formula defined from a variable
I have been stymied by an error that traces back to predict.lme, running inside a function, failing to interpret a formula based on a variable that has been passed from outside the function. I know ...
2
votes
1
answer
234
views
Programming on the data.table with "env" in a function
I am interested in joining two data.tables in a function. However, when using the new env for programming on the data.table, I am unable to join the data.tables in a function because the argument I ...
1
vote
1
answer
109
views
How to refer to the .GlobalEnv of the session using callr::r
My understanding of callr::r is that the function I am providing is evaluated in a new session of R. If (for whatever reason) I want to keep the .GlobalEnv of this session, I thought I could do it ...
0
votes
0
answers
136
views
Defined variable in shiny app is not defined
I am trying to use the variable Z in my shiny app, but it says the variable doesn't exist. I clearly defined it a few lines above the lme call. Does anyone know why the value of Z is not preserved?
#
#...