Re: [R] Trying to learn how to write an "advanced" function

2023-03-16 Thread Bert Gunter
In addition to what has already been suggested, you can use debug (and subsequently undebug) to browse a function step by step to see what each step of the function is doing. For your specific query about match.call(), I suspect that your 'puzzlement' is that you don't know what a function call is

Re: [R] Trying to learn how to write an "advanced" function

2023-03-16 Thread Greg Snow
y and z look like > rbind(x,y,z) > > # run formula y~x > JD <- doit(y~x) > JD > > # run formula y~x+z > JD2 <- doit(y~x+z) > JD2 > > > > ____________________ > From: R-help on behalf of Rasmus Liland > > Sent: Thursday, March 16, 2023 8:42 AM > To: r-help > Subj

Re: [R] Trying to learn how to write an "advanced" function

2023-03-16 Thread Ivan Krylov
В Thu, 16 Mar 2023 14:53:33 + "Sorkin, John" пишет: > I am trying to run the lm function on two different formulae: > 1) y~x, > 2) y~x+z A formula is already an unevaluated object that doesn't need further quoting; thus it can be passed around like a normal variable. It consists of a call t

Re: [R] Trying to learn how to write an "advanced" function

2023-03-16 Thread Berwin A Turlach
G'day John, For these snippets to produce what I think you want them to produce it is just necessary to define doit() as follows: doit <- function(x){ lm(formula=x) } R> # run formula y~x R> JD <- doit(y~x) R> JD Call: lm(formula = x) Coefficients: (Intercept)x 0.8403

Re: [R] Trying to learn how to write an "advanced" function

2023-03-16 Thread Greg Snow
The first thing to understand is that despite similarity in names, `match` and `match.call` are doing very different things, which should not be confused with each other. For understanding what a function is doing, it is helpful to watch what it does at each step. With functions like `lm` that ar

Re: [R] Trying to learn how to write an "advanced" function

2023-03-16 Thread Sorkin, John
t x, y and z look like rbind(x,y,z) # run formula y~x JD <- doit(y~x) JD # run formula y~x+z JD2 <- doit(y~x+z) JD2 From: R-help on behalf of Rasmus Liland Sent: Thursday, March 16, 2023 8:42 AM To: r-help Subject: Re: [R] Trying to learn how to wr

Re: [R] Trying to learn how to write an "advanced" function

2023-03-16 Thread Rasmus Liland
On 2023-03-16 12:11 +, Sorkin, John wrote: > (1) can someone point me to an > explanation of match.call or match > that can be understood by the > uninitiated? Dear John, the man page ?match tells us that match matches the first vector against the second, and returns a vector of indecie

Re: [R] Trying to learn how to write an "advanced" function

2023-03-16 Thread Ivan Krylov
В Thu, 16 Mar 2023 12:11:35 + "Sorkin, John" пишет: > (1) can someone point me to an explanation of match.call or match > that can be understood by the uninitiated? (2) can someone point me > to a document that will help me learn how to write an "advanced" > function? By "advanced" functions

[R] Trying to learn how to write an "advanced" function

2023-03-16 Thread Sorkin, John
I am trying to understand how to write an "advanced" function. To do so, I am examining the lm fucnction, a portion of which is pasted below. I am unable to understand what match.call or match does, and several other parts of lm, even when I read the help page for match.call or match. (1) can