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

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Thu Mar 16 17:16:35 CET 2023


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 exactly. The
references you were given or even an internet search would help with
that.Perhaps this also might be useful:

f <- function(x,yikes,wt=3,...) match.call()
z <- f(y = 0, x = 2, more = 'a')
z
str(z)
as.list(z)

Cheers,
Bert



On Thu, Mar 16, 2023 at 5:16 AM Sorkin, John <jsorkin using som.umaryland.edu>
wrote:

> 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 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?
>
> Thank you,
> John
>
> > lm
> function (formula, data, subset, weights, na.action, method = "qr",
>     model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE,
>     contrasts = NULL, offset, ...)
> {
>     ret.x <- x
>     ret.y <- y
>     cl <- match.call()
>     mf <- match.call(expand.dots = FALSE)
>     m <- match(c("formula", "data", "subset", "weights", "na.action",
>         "offset"), names(mf), 0L)
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list