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

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

2023-03-16 Thread Greg Snow
I think the tricky part here is the different types of `quote`. I would use `bquote` here, try: doit <- function(x){ ds <- deparse(substitute(x)) cat("1\n") print(ds) eval(bquote(lm(.(ds))),parent.frame()) } Just note that getting the parent.frame() portion right in anything more

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

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

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

2023-03-16 Thread Sorkin, John
Although I owe thanks to Ramus and Ivan, I still do not know how to write and "advanced" function. My most recent try (after looking at the material Ramus and Ivan set) still does not work. I am trying to run the lm function on two different formulae: 1) y~x, 2) y~x+z Any corrections would be

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

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"

[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)