similar to: Variable scoping question

Displaying 20 results from an estimated 1600 matches similar to: "Variable scoping question"

2010 Apr 13
1
Using object.size inside a function
When I encounter memory errors, I like to see the size of the objects in memory, so I modified one of the examples: z <- sapply(ls(), function(x) object.size(get(x))) as.matrix(rev(sort(z))[1:10]) This works fine if I run it as is, but if I try to place it inside a function, I get an error (see below). I tried using sort.list and unlist, but I couldn't get it to work. I
2011 Sep 08
3
How to specify a variable name in the regression formula without hard coding it
I have a matrix called mat and y is the column number of my response and x is a vector of the column numbers of my terms. The variable name of y can change, so I don't want to hardcode it. I can find out the name as follows: > names(mat)[y] [1] "er12.l" Then I can run the regression by hard coding the variable name as follows: > mod <-
2007 May 12
0
How to Derive an S4 Class from a data.frame?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello R-Help: I would really appreciate some help on this. I have spent a good deal of time searching for an answer for what I would think to be a common practice: Subclasses an S4 class from a data.frame. But have found very little. Here is some sample code that I've been trying: setClass("MyDataFrame",
2014 Jun 20
3
[LLVMdev] Passing specific register for an Instruction in target description files.
Hi all, I want to generate an assembly instruction for my target using target description representation of the instruction. The problem is that I want to add direct register to be chose as an output register for my target. Does it possible to do with an instruction definition in TARGETInstrInfo.td file? May be someone could help with an example? Currently I have seen that we can pass the name
2007 Oct 03
2
Change title size in plot(model)?
I want to use the plot(model) function to generate Tukey-anscomb and Q-Q plots of a lm(). I manage to change all labels but the main one which apparently is neither main or sub. So far I have tried as par setting: cex (changes symbol size within the plot), cex.main (no effect), cex.sub (no effect) cex.lab (changes label size), cex.axis (changes axis label size). What I would like to change is the
2014 Jul 02
2
[LLVMdev] Passing specific register for an Instruction in target description files.
On Mon, Jun 30, 2014 at 02:40:43AM -0700, Quentin Colombet wrote: > Hi Arsen, > > > > On Jun 19, 2014, at 10:43 PM, Arsen Hakobyan <artinetstudio at gmail.com> wrote: > > > > Hi all, > > > > I want to generate an assembly instruction for my target using target > > description representation of the instruction. The problem is that I want to
2005 Jul 03
2
demo(scoping)
entercount an error with demo(scoping). > demo(scoping) demo(scoping) ---- ~~~~~~~ ___snip_____ > ross$balance() Your balance is 120 > try(ross$withdraw(500)) Error in ross$withdraw(500) : You don't have that much money! > version _ platform i486-pc-linux-gnu arch i486 os linux-gnu system i486, linux-gnu status beta major 2 minor
2003 Oct 09
0
Scoping Rules: Summary
Thanks to Andy Liaw, Roger Peng, Thomas Lumley, Brian Ripley and Peter Dalgaard, all of whom addressed my questions or threads arising from them. The full messages were posted to the list so this is a brief summary: Andy Liaw explained the difference between lexical and dynamic scoping and the rationale behind the choice of lexical scoping for R. Roger Peng showed how to modify fnB. Brian
2000 Jul 06
0
Scoping problem?
I have to admit, I'm not too familiar with all the scoping issues in R. Luckily, I managed to write scripts/functions that didn't touch the hairy scoping details. However, in a couple of functions I'm writing now, I think I stumbled upon a problem related to scoping. To demonstrate, the following code results in a "Error in paste("png::", filename, sep = "") :
2007 Jan 07
1
Scoping issues
Hi everyone, I'm trying to split up a large R file that implements a tcl/tk gui into several smaller ones. The problem is that the main GUI creation function defines many tclVars and tkframes that need to be accessible to functions that are currently defined in main function, but which I'd like to move to different source files. These files make up a package, so it seems that using
2009 Jan 26
2
name scoping within dataframe index
Every time I have to prefix a dataframe column inside the indexing brackets with the dataframe name, e.g. df[df$colname==value,] -- I am wondering, why isn't there an R scoping rule that search starts with the dataframe names, as if we'd said with(df, df[colname==value,]) -- wouldn't that be a reasonable default to prepend to the name search path? Cheers, Alexy
2023 Mar 18
1
lexical scoping for scripts......
Dear members, The documentation for source() says: Input is read and parsed from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment. What does this mean? I presume that any objects that are CREATED by the script are stored in the Global environment (if local = FALSE), but the rules for
2023 Mar 18
1
lexical scoping for scripts......
On 18/03/2023 1:57 p.m., akshay kulkarni wrote: > Dear members, > The documentation for source() says: > > Input is read and parsed from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment. > > What does this mean? I presume that any objects that are CREATED by the script
1997 Aug 06
1
R-beta: ?faq example of scoping
I like Thomas' example. Kurt can you include it in the FAQ. Recently I have been doing a lot of programming that has required either optimization or zero-finding. Unfortunately most of the functions need some arguments to be optimized over and have other parameters that depend on the data but are fixed with respect to optimization. With R scoping rules this is a trivial problem; simply
1997 Aug 06
1
R-beta: ?faq example of scoping
I like Thomas' example. Kurt can you include it in the FAQ. Recently I have been doing a lot of programming that has required either optimization or zero-finding. Unfortunately most of the functions need some arguments to be optimized over and have other parameters that depend on the data but are fixed with respect to optimization. With R scoping rules this is a trivial problem; simply
2004 Mar 10
1
Question concerning library function "nlme" and lexical scoping
I am running into problems calling the library function nlme from within another function. Basically,the following function (with v a list containing data and initialization values) > testfunc function(dat=v) { test<-nlsList(result~a+(b-a)/(1+(conc/(c+z*cdiff))^d) |rep,start=dat$init,data=dat$mixeddat) return(nlme(test,random=b~1)) } produces the error message Error in eval(expr, envir,
2011 Mar 16
2
Detecting bad lexical scoping
I've recently hunted down a troublesome bug in my own code, and am looking for an easy mechanism to detect this kind of error in other R code. The problem was an undefined variable inside of a function. Unfortunately, R looked for that variable in the global environment and found it since there was variable with that name in my testing scripts (note to self: do not name things "x").
2007 May 24
1
Search scoping in acts_as_ferret
Hello, I am exploring acts_as_ferret, and the first question that pops to mind is scoping, i.e. how to restrict searches in various ways. For example, I have a Post model with title, content, and user_id as attributes, and I want users to be able to search through their own posts only. Normally, of course, I would do Post.find(:all, :conditions=>["user_id=?", current_user],
2013 Mar 30
0
Scoping issue with irf() from {vars}
Dear all: There seems to be a problem with scoping, for irf() in vars, when called within a function. Try the following: ----------------------- testfun <- function(lags){ data(Canada) var.2c <- VAR(Canada, p = lags, type = "const") print(var.2c) } testfun(lags=3) ## Everything OK. Now this: testfun2 <- function(lags){ data(Canada) var.2c <- VAR(Canada, p = lags, type =
2003 Mar 17
1
scoping rules
Hi I recently found a bug that was isomorphic to the following: ll1 <- 2 increment <- function(x) { l11 <- 1 return(x+ll1) #bug here } Of course, R is obeying the scoping rules just fine, but I'm evidently not setting the do.what.I.mean.not.what.I.say variable correctly. Now, how do I avoid making this type of error? ... and what is the best tool for tracking it down? --