How can a non-imported method in a not-attached package be found by calls to functions not having it in their namespace?

I’m not sure if I correctly understand your question, but the main point is that group is character vector while data$group is factor. After attaching gmodels, the call for reorder(factor) calls gdata:::reorder.factor. so, reorder(factor(group)) calls it. In transform, the function is evaluated within the environment of the first argument, so in T2 <- transform(data, group … Read more

How do you use “

<<- is most useful in conjunction with closures to maintain state. Here’s a section from a recent paper of mine: A closure is a function written by another function. Closures are so-called because they enclose the environment of the parent function, and can access all variables and parameters in that function. This is useful because … Read more

What is lexical scope?

I understand them through examples. 🙂 First, lexical scope (also called static scope), in C-like syntax: void fun() { int x = 5; void fun2() { printf(“%d”, x); } } Every inner level can access its outer levels. There is another way, called dynamic scope used by the first implementation of Lisp, again in a … Read more