Displaying 20 results from an estimated 3000 matches similar to: "my function decided to stop working, problem with scoping?"
2010 Jul 02
2
S4 classes and debugging - Is there a summary?
Dear all,
I'm getting more and more frustrated with the whole S4 thing and I'm
looking for a more advanced summary on how to deal with them. Often I
get error messages that don't make sense at all, or the code is not
doing what I think it would do. Far too often inspecting the code
requires me to go to the source, which doesn't really help in easily
finding the bit of code
2010 Aug 26
1
Passing arguments between S4 methods fails within a function:bug? example with raster package.
Dear all,
This problem came up initially while debugging a function, but it
seems to be a more general problem of R. I hope I'm wrong, but I can't
find another explanation. Let me illustrate with the raster package.
For an object "RasterLayer" (which inherits from Raster), there is a
method xyValues defined with the signature
2012 Sep 29
1
About the scope of a variable and the save() method
In the following test, the variable x is supposed to be modified within the
function test.save.x. It works as expected util using the save command.
# initialize x.file
x <- 1
save(x, file="x.file")
rm(x) # Remove x from R_GlobalEnv
exists("x") # FALSE
# define test
test.save.x <- function(){
save.x <- function(){
save(x, file="x.file")
}
change.x <-
2023 Apr 05
1
on lexical scoping....
It seems mostly correct. Here are a few quibbles:
- I don't think "owner" is a good description of the parent environment.
Usually when I use owner in computing, there's an implication that the
owner controls what it owns, is responsible for allocating and
destroying it, etc. Parent environments are targets of a pointer from
other environments that list them as their
2009 Sep 29
3
How do I access class slots from C?
Hi
I'm trying to implement something similar to the following R snippet using
C. I seem to have hit the wall on accessing class slots using C.
library(fPortfolio)
lppData <- 100 * LPP2005.RET[, 1:6]
ewSpec <- portfolioSpec()
nAssets <- ncol(lppData)
setWeights(ewSpec) <- rep(1/nAssets, times = nAssets)
ewPortfolio <- feasiblePortfolio(
data = lppData,
spec = ewSpec,
2009 Sep 16
2
I want to get a reference to this time series object
I'm trying to get a reference to this object in C
SWX.RET[1:6,c("SBI,"SPI","SII")]
While i am able to access and use a plain SWX.RET object, I'm getting
confused on how to create an object with the array subscripts like above.
Here is what I tried to do. It doesn't work because "[" is obviously not an
operation or function on SWX.RET. So how do I
2016 Dec 12
2
why does parent.frame() cycle when called from inside capture.output()?
Hello R devel/help,
I ran into this strange behavior:
# showstack is supposed to walk through the stack of parent
# environments when it is called:
showstack = function() {
env = environment()
for(i in 1:12) {
env = do.call(parent.frame, list(), env=env)
print(env)
}
}
# a simple chain of functions:
g3=function(t) showstack()
2016 Dec 12
2
why does parent.frame() cycle when called from inside capture.output()?
Hello R devel/help,
I ran into this strange behavior:
# showstack is supposed to walk through the stack of parent
# environments when it is called:
showstack = function() {
env = environment()
for(i in 1:12) {
env = do.call(parent.frame, list(), env=env)
print(env)
}
}
# a simple chain of functions:
g3=function(t) showstack()
2015 Oct 09
4
A where() functions that does what exists() does but return the environment when object lives?
Hi,
exists("foo", inherits=TRUE) check whether an object named "foo"
exists, and get("foo", inherits=TRUE) retrieves it. I'm looking for a
similar function to exists() that returns the environment where the
object "foo" exists, iff at all. If not found, NULL is returned.
Does that exist?
EXAMPLE #1:
> sample2 <- base::sample
> env <-
2014 May 17
1
environment question
According to
:https://stat.ethz.ch/R-manual/R-devel/library/base/html/environment.html
"If |fun| is a function or a formula then |environment(fun)| returns the
environment associated with that function or formula. If |fun| is |NULL|
then the current evaluation environment is returned."
> environment()
<environment: R_GlobalEnv>
> environment(environment)
2020 Mar 24
2
help with rchk warnings on Rf_eval(Rf_lang2(...))
> Shield<SEXP> res(Rcpp_fast_eval(Rf_lang2(asEnvironmentSym, x), R_GlobalEnv));
The call should be protected before evaluation though. So more like:
Shield<SEXP> call(Rf_lang2(asEnvironmentSym, x));
return Rcpp_fast_eval(call, R_GlobalEnv);
Best,
Lionel
On 3/23/20, Dirk Eddelbuettel <edd at debian.org> wrote:
>
>
> On 23 March 2020 at 17:07, Ben Bolker wrote:
>
2016 Dec 08
2
methods(`|`) lists all functions?
Dear R-Devel,
I was attempting an exercise in Hadley Wickam's book "Advanced R". The
exercise is to find the generic with the greatest number of methods.
I found that 'methods(`|`)' produces a list of length 2506, in R
3.3.1. Similar behavior is found in 3.4.0. It seems to include all
functions and methods. I imagine something is being passed to "grep"
without
2015 Oct 13
1
A where() functions that does what exists() does but return the environment when object lives?
On Sat, Oct 10, 2015 at 1:24 AM, Uwe Ligges
<ligges at statistik.tu-dortmund.de> wrote:
> I'd start looking at getAnywhere().
Thanks Uwe, that does indeed provides "where" information.
Unfortunately, I don't see how it will allow me to search environments
similarly/in the same order as exists/get(..., envir, inherits=TRUE)
does it. getAnywhere() will search everything
2006 May 17
1
protect/unprotect howto in C code
Hi,
Im currently trying to debug a 'error in unprotect: stack imbalance' problem
and I am curious about two basic questions on the use of PROTECT and
UNPROTECT, which I could not figure out:
- which objects have to be protected, namely, if the code is something like:
SEXP fun, e;
/* get the expression e ... */
fun = eval(e, R_GlobalEnv);
/* or like this?: PROTECT(fun = eval(e,
2005 Jan 17
5
find source code
I am using R 2.0.2 on a WinXP
I am trying to get the code of the Kruskal-Wallis test but
> kruskal.test
function (x, ...)
UseMethod("kruskal.test")
<environment: namespace:stats>
> ls(3)
[1] "acf" "acf2AR" "add.scope"
..............
[181] "kruskal.test" "ks.test"
2004 Oct 08
2
R-2.0.0 findVar and findFun question
Dear all,
when working on a project with embedded R, I found out that R-2.0.0 causes
a problem where older versions worked OK.
Rf_findVar(...) causes the following error when used to find a generic function
(such as print):
fun = Rf_findVar(...);
R_tryEval(fun, ...);
Error in function (object, ...) : Invalid generic function in usemethod
Alternatively, using Rf_findFun(...) seems OK in this
2009 Jan 08
1
Callbacks seems to get GCed.
Dear list,
I am trying to implement a publish-subscribe mechanism in for an embedded
R interpreter. But somehow my registered closures seem to get collected by
the GC, even though I have protected them. I have reducted my code to the
following sample. Sorry if it is a little verbose.
The first couple of call of calls still work, but at some point one of the
callbacks (callback1 in my
2010 Apr 27
2
when setting environment: target of assignment expands to non-language object
Hi,
I am trying to place my own functions in the nlme environment:
The following statement works:
environment(coef.corSPT) <- environment(getS3method("coef","corSpatial"))
but this one returns an error:
environment(get("coef<-.corSPT")) <-
environment(getS3method("coef<-","corSpatial"))
Error in
2014 Jun 25
1
Need help on calling Head from C
Hi ,
I am trying to call head function from C . My doubt is with the parameter
n,how to pass it .
PROTECT(dfm=lang3(install("data.frame"),df,ScalarLogical(FALSE)));
SET_TAG(CDDR(dfm), install("stringsAsFactors")) ;
SEXP res = PROTECT(eval(dfm,R_GlobalEnv));
PROTECT(head=lang3(install("head"),res,ScalarInteger(1)));
head = PROTECT(eval(head,R_GlobalEnv));
I tried
2013 Aug 14
1
local variable assignment: first copies from higher frame?
hi all -- this might not be the correct list for this
question/discussion, though R-help didn't seem like the correct venue,
either, so...
i'm looking for just some extra clarification of how local variables
are defined/bound, beyond the simple cases given in the Language
document.
the particular instance is when there is variable assignment inside a function.
normally, this creates a