similar to: Question on closure (lexical scoping) and encapsulation

Displaying 20 results from an estimated 10000 matches similar to: "Question on closure (lexical scoping) and encapsulation"

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
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
2023 Mar 19
1
lexical scoping for scripts......
Dear Duncun, thanks for the reply.... So when I run a script in the system command line by R CMD BATCH, the objects created in the script cannot be stored in the workspace ,right? If yes, how to save them? Moreover, the only way to save the objects CREATED from the script permanently is to save them to the disk, right? THanking you, yours sincerely, AKSHAY M KULKARNI
2023 Mar 19
1
lexical scoping for scripts......
On 19/03/2023 2:33 p.m., akshay kulkarni wrote: > Dear Duncun, > ? ? ? ? ? ? ? ? ? ? ? ? ?thanks for the reply.... > > So when I run a script in the system command line by R CMD BATCH, the > objects created in the script cannot be stored in the workspace ,right? > If yes, how to save them? Moreover, the only way to save the objects > CREATED from the script permanently is
2023 Mar 19
1
lexical scoping for scripts......
On 19/03/2023 2:55 p.m., akshay kulkarni wrote: > Dear Duncun, > ? ? ? ? ? ? ? ? ? ? ? ? ?What if there is no interactive "session" > running? I will be running my scripts automatically from crontab in Linux. I was talking about the session that is created for the duration of the BATCH run, not some other session that may be running in another process. Sorry for the
2000 Mar 26
2
hist2d() function in R?
Dear R users, I am just starting with R (v. 1.0.0) and I use Vehables & Ripley's MASS book for examples. In the intro session, there is an example of a 2D histogram on an 8x8 grid: x <- rnorm(1000) y <- rnorm(1000) contour(hist2d(x,y,,,8,8)) R complains: Error in contour(hist2d(x, y, , , 8, 8)) : couldn't find function "hist2d" I looked for hist2d() in the
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").
2000 Oct 10
1
Adding a new column to data frame (recoding)
Dear R users, I have a very simple question. What is the easiest way to recode data in one of the columns of a data frame and put it into a new column? For example, here is a simple data frame: var1 1 1 2 2 3 3 How do I add a new column to data - 'var2' in which I group values in 'var1', for example: var1 var2 1 1 4 2 2 4 3 3 5 It's got to
2023 Mar 19
2
lexical scoping for scripts......
Dear Duncun, What if there is no interactive "session" running? I will be running my scripts automatically from crontab in Linux. THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Duncan Murdoch <murdoch.duncan at gmail.com> Sent: Monday, March 20, 2023 12:20 AM To: akshay kulkarni <akshay_e4 at hotmail.com>; R
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,
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
2003 Feb 28
2
Lexical scoping question
Hello, Could someone please tell me what I am thinking about incorrectly: f <- function(y) { g <- function(x) x + y g } In the following, I get what I expect based on my understanding of lexical scoping: (f(1))(3) # 4 (f(2))(3) # 5 But now, fs <- lapply(c(1, 2), f) fs[[1]](3) # 5 (Why not 4 ?) fs[[2]](3) # 5 Checking the environments of these functions, I see that
2023 Mar 19
1
lexical scoping for scripts......
What do _you_ mean when you use the term "interactive"? Because R distinguishes between executing code in a function and executing code from the global environment, but it does not care whether a person is doing the typing or not. I get the feeling that you think of your R code in terms of "scripts" when you should be thinking of your code in terms of functions. What
2023 Mar 19
1
lexical scoping for scripts......
Dear Jeff, I will not be running R command in the shell prompt. So there is no banner, no > prompt. Just running "myscript.R" from the shell prompt. or from crontab in Linux. I think you get the context..... thanking you, yours sincerely AKSHAY M KULKARNI ________________________________ From: Jeff Newmiller <jdnewmil at dcn.davis.ca.us> Sent: Monday, March
2023 Mar 19
1
lexical scoping for scripts......
Again, the answer is "interactivity does not matter". On March 19, 2023 12:54:28 PM PDT, akshay kulkarni <akshay_e4 at hotmail.com> wrote: >Dear Jeff, > I will not be running R command in the shell prompt. So there is no banner, no > prompt. Just running "myscript.R" from the shell prompt. or from crontab in Linux. I think you get the
2023 Apr 04
1
on lexical scoping....
No, there are lots of situations where that doesn't make sense. You don't want to have to define local copies of the functions from every package you use, for example. I think the takeaway is to learn how R scoping works, and keep things simple. That's one reason I tend to avoid "tidyverse" packages. There are a lot of really good ideas in those packages, but
2023 Apr 04
1
on lexical scoping....
Dear Duncan, THanks for the reply...! So the takeaway is that define the symbol in the same environment before using it right!? Thanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Duncan Murdoch <murdoch.duncan at gmail.com> Sent: Tuesday, April 4, 2023 8:21 PM To: akshay kulkarni <akshay_e4 at hotmail.com>; Deepayan Sarkar
2023 Apr 04
1
on lexical scoping....
You can't change the basic way R searches, but you can ask for a different kind of search. For example, to see if "x" exists, you can use exists("x") and it will do the default search, but exists("x", inherits = FALSE) will only look in the current environment. The get() function has a similar argument which returns the value Unfortunately these
2023 Apr 04
1
on lexical scoping....
Dear Deepayan, THanks for the pithy, pointed reply. But isn't it risky? Can I somehow get a warning when x is not defined in the global environment but takes on a value from one of the loaded packages? any packages for that? THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Deepayan Sarkar <deepayan.sarkar at
2000 Dec 14
1
How do I track a segfault?
Dear R users, I have to catch a nasty bug and would appreciate any advice or help! I get a segfault (core dumped) that happens in one of my own functions. The problem is, it does not happen most of the time, only sometimes, so it's very hard to reproduce. Or it may run ok in interactive mode, but bug out in batch mode. Also, it tends to happen more on the slower of my 2 machines (PII 266),