foo This snippet is failed through error indevelopment "attempt to apply non-function".Actually, data$substitute(attr) failed to acquire the attr attribute of lst.

You are watching: Attempt to apply non-function

The concrete example is as following:Let us develop a list called lst.

lst Then lst$substitute(CLICK_DT) fairesulted in attain the CLICK_DT attribute of lst.

foo(lst, CLICK) must transdevelop lst$CLICK into element mode and also foo(lst,CLICK_DT) have to transdevelop lst$CLICK_DT into aspect mode.

What is the easy means to perform this? Thanks.


r
Share
Improve this question
Follow
edited Aug 5 "15 at 7:53
user1903382
asked Aug 5 "15 at 7:23
*

user1903382user1903382
7511 gold badge22 silver badges1010 bronze badges
6
| Sjust how 1 more comment

2 Answers 2


Active Oldest Votes
1
In your code, information and attr are two different variables being passed right into the attribute - attr is not an attribute (i.e. a column) in data. So, instead simply carry out this:

foo ...and you"re done (in truth, if this is all your attribute will certainly be doing, you execute not also must pass in that information variable, and using just function(attr) will certainly occupational simply fine).

Then, if attr is supposed to be a column in your data structure, then use the $ authorize as soon as passing a variable to the function thus:

# declare the functionfoo Hope this helps!


Share
Improve this answer
Follow
edited Aug 5 "15 at 7:43
answered Aug 5 "15 at 7:38
*

Deolu ADeolu A
64411 gold badge55 silver badges1010 bronze badges
Add a comment |
0
I see you"re trying to apply non-standard dispute testimonial utilizing substitute() to permit specifying the targain list component utilizing an unquoted symbol as the second argument of foo(). Here"s exactly how to do that:

foo Couple of additional points: You"re misusing the word "attribute". In R, "attribute" is a well-identified term that describes a secondary information object that is attached to an additional (primary) data object. You have the right to read/write the qualities of an item using attr() and attributes(). The word you have to be using below is "component", since we"re talking around list components. You can also use the word "element", considering that lists are regarded as a sort of vector, and are even referred to as "generic vectors" in the R source.

Secondly, the dollar operator is actually a role. When you use substitute() to access the parse tree of an expression, if the expression requires the dollar operator, then the type of the rerevolve value will be "language" (via course "call" or "{" if surrounded by a braced block), fairly than "symbol" (class "name"). This is additionally true of normal attribute calls, for example typeof(substitute(sum(1,2))) additionally retransforms type "language" (and also also has actually course "call").

See more: List Of Ghost Hunters All Aboard The Ghost Train — Temporarily Closed

Tright here are various ways your necessity might be imposed. You can support a literal string, or a symbol (as I showed), or even use some kind of innovative analysis of the parse tree of the discussion, such as accepting a dollar speak to and extracting from the resulting parse tree the RHS, and using that symbol as the component name. You can even via type detection of the argument"s parse tree support some or every one of these interfaces with a single function definition, although that would certainly add intricacy. I do not think that would certainly be worth it; the means I created foo() over I think is the finest design, because the implementation is straightforward, however it additionally provides maximum convenience for the caller, given that they can specify the targain list component utilizing an unquoted symbol.