similar to: Calling a replacement function in a custom environment

Displaying 20 results from an estimated 5000 matches similar to: "Calling a replacement function in a custom environment"

2023 Aug 27
1
Calling a replacement function in a custom environment
I think there isn't a way to make this work other than calling `is.na<-` explicitly: x <- b$`is.na<-`(x, TRUE) It seems like a reasonable suggestion to make b$is.na(x) <- TRUE work as long as b is an environment. If you wanted it to work when b was a list, it would be more problematic because of partial name matching. E.g. suppose b was a list containing functions
2016 Oct 04
0
On implementing zero-overhead code reuse
Check out ?klmr/modules? on Github (distinct from CRAN?s ?modules?!). It looks pretty much exactly like what you want: https://github.com/klmr/modules It has an extensive README and vignette explaining the usage. Cheers, Konrad -- Konrad Rudolph On Sun, 2 Oct 2016 at 18:31 Kynn Jones <kynnjo at gmail.com> wrote: > I'm looking for a way to approximate the
2015 Dec 10
6
How do I reliably and efficiently hash a function?
I?ve got the following scenario: I need to store information about an R function, and retrieve it at a later point. In other programming languages I?d implement this using a dictionary with the functions as keys. In R, I?d usually use `attr(f, 'some-name')`. However, for my purposes I do not want to use `attr` because the information that I want to store is an implementation detail that
2016 Oct 02
5
On implementing zero-overhead code reuse
I'm looking for a way to approximate the "zero-overhead" model of code reuse available in languages like Python, Perl, etc. I've described this idea in more detail, and the motivation for this question in an earlier post to R-help (https://stat.ethz.ch/pipermail/r-help/2016-September/442174.html). (One of the responses I got advised that I post my question here instead.) The
2015 Dec 11
1
How do I reliably and efficiently hash a function?
In addition to what Charles wrote, you can also use 'local' if you don't want a function that creates another function. > f <- local({info <- 10; function(x) x + info}) > f(3) [1] 13 best, Mark Op vr 11 dec. 2015 om 03:27 schreef Charles C. Berry <ccberry at ucsd.edu>: > On Thu, 10 Dec 2015, Konrad Rudolph wrote: > > > I?ve got the following scenario:
2019 Mar 23
4
topenv of emptyenv
I was surprised just now to find out that `topenv(emptyenv())` equals ? `.GlobalEnv`, not `emptyenv()`. From my understanding of the description of `topenv`, it should walk up the chain of enclosing environments (as if by calling `e = parent.env(e)` repeatedly; in fact, that is almost exactly its implementation in envir.c) until it hits a top level. However, `emptyenv()` has no enclosing
2014 Sep 21
1
Bug in new behaviour for all.equal and environments?
Hi R-devel, The following code: all.equal(baseenv(), baseenv()) gives the error when run in a clean R session with latest R-devel (r66650): kevin:~$ R --vanilla --slave -e "all.equal(baseenv(), baseenv())" Error in all.equal.envRefClass(target[[i]], current[[i]], check.attributes = check.attributes, : attempt to apply non-function Calls: all.equal ...
2020 Jan 10
1
Operator precedence of =, <- and ?
The documentation (help("Syntax")) gives the operator precedence of the assignment operators and help, from highest to lowest, as: ?<- <<-? assignment (right to left) ?=? assignment (right to left) ??? help (unary and binary) If I understand correctly this implies that `a = b ? c` and `a <- b ? c` should parse
2005 Nov 04
1
Changes to environments in R-devel
I've just committed some changes to R-devel which affect environments. Specifically: - using NULL as an environment is now deprecated: use baseenv() instead. (baseenv() is already available in R 2.2.0, where it returns NULL. For most purposes it retains the same meaning in R-devel.) If you do use NULL, it will be converted to baseenv(), and a warning printed. For example: > f
2019 Oct 09
2
S3 lookup rules changed in R 3.6.1
tl;dr: S3 lookup no longer works in custom non-namespace environments as of R 3.6.1. Is this a bug? I am implementing S3 dispatch for generic methods in environments that are not packages. I am trying to emulate the R package namespace mechanism by having a ?namespace? environment that defines generics and methods, but only exposes the generics themselves, not the methods. To make S3 lookup work
2010 Feb 25
2
proto and baseenv()
I understand why the following happens ($.proto delegates to get, which ascends the parent hierarchy up to globalenv()), but I still find it anti-intuitive: > z <- 1 > y <- proto(a=2) > y$z [1] 1 Although this is well-documented behavior; wouldn't it uphold the principle of least surprise to inherit instead from baseenv() or emptyenv()? (See attached patch.) Spurious
2006 Apr 11
1
eapply() fails on baseenv() (PR#8761)
eapply() works on most environments, but not on baseenv(). For example, > x <- 1 > eapply(globalenv(), function(x) x) $x [1] 1 > eapply(baseenv(), function(x) x) list() I'm probably not going to have time to work on this before 2.3.0, but I don't think it's really urgent; if no one else fixes it first I'll do it after the release. Duncan Murdoch
2008 Sep 27
1
seg.fault from nlme::gnls() {was "[R-sig-ME] GNLS Crash"}
>>>>> "VW" == Viechtbauer Wolfgang (STAT) <Wolfgang.Viechtbauer at STAT.unimaas.nl> >>>>> on Fri, 26 Sep 2008 18:00:19 +0200 writes: VW> Hi all, I'm trying to fit a marginal (longitudinal) VW> model with an exponential serial correlation function to VW> the Orange tree data set. However, R crashes frequently VW>
2020 Aug 10
1
lm() takes weights from formula environment
Thank you for your suggestion. I do know how to work around the issue. I usually build a fresh environment as a child of base-environment and then insurt the weights there. I was just trying to provide an example of the issue. emptyenv() can not be used, as it is needed for the eval (errors out even if weights are not used with "could not find function list"). For some applications
2006 Apr 04
2
Return function from function with minimal environment
Hi, this relates to the question "How to set a former environment?" asked yesterday. What is the best way to to return a function with a minimal environment from a function? Here is a dummy example: foo <- function(huge) { scale <- mean(huge) function(x) { scale * x } } fcn <- foo(1:10e5) The problem with this approach is that the environment of 'fcn' does not
2020 Aug 10
3
lm() takes weights from formula environment
I wish I had started with "I am disappointed that lm() doesn't continue its search for weights into the calling environment" or "the fact that lm() looks only in the formula environment and data frame for weights doesn't seem consistent with how other values are treated." But I did not. So I do apologize for both that and for negative tone on my part. Simplified
2008 Jul 29
1
environment question
Hi R users! I was looking at some of the example code for the "environment" function. Here it is: e1 <- new.env(parent = baseenv()) # this one has enclosure package:base. e2 <- new.env(parent = e1) assign("a", 3, envir=e1) ls(e1) ls(e2) exists("a", envir=e2) # this succeeds by inheritance exists("a", envir=e2, inherits = FALSE)
2018 Dec 21
2
Bug report: R.home() cause package Rcpp failed executing sourceCpp, similar bug are labeled "BUG 16660" since 2016 and here I could provide a solution that tested in my laptop.
https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16660 Here is the bug, which R.home may generate a path contains a whitespace. this will cause Rcpp failed executing sourceCpp > sourceCpp("b:/2018-12-14/src/18020/MCMC.cpp") Error in system(cmd, intern = !showOutput) : 'D:/Program' not found Error in system(cmd, ignore.stderr = TRUE, intern = TRUE) :
2007 Jan 09
4
A question about R environment
Hi all, I created environment "mytoolbox" by : mytoolbox <- new.env(parent=baseenv()) Is there anyway I put it in the search path ? If you need some background : In a project, I often write some small functions, and load them into my workspace directly, so when I list the objects with ls(), it looks pretty messy. So I am wondering if it is possible to creat an
2011 Mar 11
1
dataframe to a timeseries object
I?m wondering which is the most efficient (time, than memory usage) way to obtain a multivariate time series object from a data frame (the easiest data structure to get data from a database trough RODBC). I have a starting point using timeSeries or xts library (these libraries can handle time zones), below you can find code to test. Merging parallelization (cbind) is something I?m thinking at