Re: [R] on lexical scoping....

2023-04-04 Thread Richard O'Keefe
R *does* search the environment stack. > search() [1] ".GlobalEnv""package:stats" "package:graphics" [4] "package:grDevices" "package:utils" "package:datasets" [7] "package:methods" "Autoloads" "package:base What you seem to be missing is that a package may contain

Re: [R] on lexical scoping....

2023-04-04 Thread Jeff Newmiller
Leading off with you can only have two things in an environment definitely indicates this should be read with a skeptical eye. Although the title of "Advanced R" may be more scary than someone writing notes on GitHub like a bro, IMHO Adv R is quite readable for anyone interested in questions

Re: [R] on lexical scoping....

2023-04-04 Thread Mark Leeds
obviously, everyone has different opinions on what's useful but I always found this document quite helpful. I think, in the past, someone said that there are some incorrect statements in but I'm not sure what they are.

Re: [R] on lexical scoping....

2023-04-04 Thread Bert Gunter
The following *might* be of use to you. If you can predict what the various function invocations will do, I think you have a reasonable grasp of how lexical scoping works in R (contrary or supplementary opinions welcome). It is the sort of thing you will find in the references also. If this is all

Re: [R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Duncan, THanks a lot..!! THanking you, Yours sincerely, AKSHAY M KULKARNI From: Duncan Murdoch Sent: Tuesday, April 4, 2023 8:49 PM To: akshay kulkarni ; Deepayan Sarkar Cc: R help Mailing list Subject: Re: [R] on lexical

Re: [R] on lexical scoping....

2023-04-04 Thread Duncan Murdoch
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"

Re: [R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
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 Sent: Tuesday, April 4, 2023 8:21 PM

Re: [R] on lexical scoping....

2023-04-04 Thread Duncan Murdoch
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

Re: [R] on lexical scoping....

2023-04-04 Thread Duncan Murdoch
On 04/04/2023 10:35 a.m., akshay kulkarni wrote: Dear Duncan,                          THanks for the reply. I am looking at the technical point. The behavior you just described, as far as I know, is only for functions right? No, not at all. Every function you write in R has an associated

Re: [R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Ducan, Very informative! THanks a lot! THanking you, Yours sincerely, AKSHAY M KULKARNI From: Duncan Murdoch Sent: Tuesday, April 4, 2023 8:14 PM To: akshay kulkarni ; R help Mailing list Subject: Re: [R] on lexical scoping On

Re: [R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Jeff, THanks a lot for the pithy reply... Thanking you, Yours sincerely, AKSHAY M KULKARNI From: Jeff Newmiller Sent: Tuesday, April 4, 2023 7:43 PM To: r-help@r-project.org ; akshay kulkarni ; R help Mailing list Subject: Re: [R] on

Re: [R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Bert, THanks a lot. I will take a look at those... THanking you, Yours sincerely, AKSHAY M KULKARNI From: Bert Gunter Sent: Tuesday, April 4, 2023 7:48 PM To: akshay kulkarni Cc: R help Mailing list Subject: Re: [R] on lexical

Re: [R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Duncan, THanks for the reply. I am looking at the technical point. The behavior you just described, as far as I know, is only for functions right? THre is no documentation ever, which says that the code looks for x in the search path. Could you please point me to

Re: [R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
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

Re: [R] on lexical scoping....

2023-04-04 Thread Deepayan Sarkar
On Tue, Apr 4, 2023 at 7:26 PM akshay kulkarni wrote: > Dear Members, > I have the following code typed at the > console prompt: > > y <- x*10 > > X has not been defined and the above code throws an object not found > error. That is, the global environment does

Re: [R] on lexical scoping....

2023-04-04 Thread Duncan Murdoch
On 04/04/2023 9:56 a.m., akshay kulkarni wrote: Dear Members, I have the following code typed at the console prompt: y <- x*10 X has not been defined and the above code throws an object not found error. That is, the global environment does not contain x. Why

Re: [R] on lexical scoping....

2023-04-04 Thread Bert Gunter
?search and ?environment See also "The R Language Definition" manual for similar such questions. -- Bert On Tue, Apr 4, 2023 at 6:56 AM akshay kulkarni wrote: > > Dear Members, > I have the following code typed at the console > prompt: > > y <- x*10 > > X has

Re: [R] on lexical scoping....

2023-04-04 Thread Jeff Newmiller
Namespaces. Packages only export specific object names from their namespaces. But few instances of x would be found there. Also, function argument lists are not added to the search path until the functions are running, and then the search path only goes through the environments in which the

[R] on lexical scoping....

2023-04-04 Thread akshay kulkarni
Dear Members, I have the following code typed at the console prompt: y <- x*10 X has not been defined and the above code throws an object not found error. That is, the global environment does not contain x. Why doesn't it look further in the environment stack,

Re: [R] Simple Stacking of Two Columns

2023-04-04 Thread Ebert,Timothy Aaron
Originally this post was to just look at execution times for different approaches to solving this problem. Now I have a question: I change the code for calculating a1 from c(c1, c2) to data.frame(c(c1,c2)). This changes the execution times of all the other variables. What am I missing?

Re: [R] Simple Stacking of Two Columns

2023-04-04 Thread Richard O'Keefe
Just to repeat: you have NamesWide<-data.frame(Name1=c("Tom","Dick"),Name2=c("Larry","Curly")) and you want NamesLong<-data.frame(Names=c("Tom","Dick","Larry","Curly")) There must be something I am missing, because NamesLong <- data.frame(Names = c(NamesWide$Name1, NamesWide$Name2))

Re: [R] Simple Stacking of Two Columns

2023-04-04 Thread Kimmo Elo
Hi, or maybe this? NamesLong<-data.frame(Names=unlist(NamesWide), row.names = NULL) HTH, Kimmo ma, 2023-04-03 kello 16:23 +, Ebert,Timothy Aaron kirjoitti: > My first thought was pivot_longer, and stack() is new to me. > How about append(c1,c2) as another solution? Or >