[R] How to get the name of the first argument in an assignment function?
Dear All! If I pass an object to an assignment function I cannot get it's name by deparse(substitute(argument)), but I get *tmp* and I found no way to get the original name, in the example below it should be va1. Is there a way? Thanks, Heinz ## example 'fu1-' - function(var, value) { print(c(name.of.var=deparse(substitute(var} fu1(va1) - 3 name.of.var *tmp* ## desired result: ## name.of.var ##va1 version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status Patched major 2 minor 3.1 year 2006 month 07 day23 svn rev38687 language R version.string Version 2.3.1 Patched (2006-07-23 r38687) __ R-help@stat.math.ethz.ch mailing list 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.
Re: [R] How to get the name of the first argument in an assignment function?
If you are willing to write fu2[Var] - 3 instead of fu2(Var) - 3 then this workaround may suffice: fu2 - structure(NA, class = fu2) [-.fu2 - function(x, ..., value) { print(match.call()[[3]]); fu2 } # test fu2[Var] - 3 # prints Var On 7/27/06, Heinz Tuechler [EMAIL PROTECTED] wrote: Dear All! If I pass an object to an assignment function I cannot get it's name by deparse(substitute(argument)), but I get *tmp* and I found no way to get the original name, in the example below it should be va1. Is there a way? Thanks, Heinz ## example 'fu1-' - function(var, value) { print(c(name.of.var=deparse(substitute(var} fu1(va1) - 3 name.of.var *tmp* ## desired result: ## name.of.var ##va1 version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status Patched major 2 minor 3.1 year 2006 month 07 day23 svn rev38687 language R version.string Version 2.3.1 Patched (2006-07-23 r38687) __ R-help@stat.math.ethz.ch mailing list 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. __ R-help@stat.math.ethz.ch mailing list 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.
Re: [R] How to get the name of the first argument in an assignment function?
At 06:10 27.07.2006 -0400, Gabor Grothendieck wrote: If you are willing to write fu2[Var] - 3 instead of fu2(Var) - 3 then this workaround may suffice: fu2 - structure(NA, class = fu2) [-.fu2 - function(x, ..., value) { print(match.call()[[3]]); fu2 } # test fu2[Var] - 3 # prints Var Thank you, Gabor for your response. My example was very reduced, just to show the point, but in the way I would like to use it, probably your solution may be difficult to apply. Seems, I have to accept that I cannot solve it. Thanks again, Heinz On 7/27/06, Heinz Tuechler [EMAIL PROTECTED] wrote: Dear All! If I pass an object to an assignment function I cannot get it's name by deparse(substitute(argument)), but I get *tmp* and I found no way to get the original name, in the example below it should be va1. Is there a way? Thanks, Heinz ## example 'fu1-' - function(var, value) { print(c(name.of.var=deparse(substitute(var} fu1(va1) - 3 name.of.var *tmp* ## desired result: ## name.of.var ##va1 version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status Patched major 2 minor 3.1 year 2006 month 07 day23 svn rev38687 language R version.string Version 2.3.1 Patched (2006-07-23 r38687) __ R-help@stat.math.ethz.ch mailing list 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. __ R-help@stat.math.ethz.ch mailing list 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.
Re: [R] How to get the name of the first argument in an assignment function?
The complexity of the function should not matter. Here is another example of this technique: http://tolstoy.newcastle.edu.au/R/help/04/06/1430.html On 7/27/06, Heinz Tuechler [EMAIL PROTECTED] wrote: At 06:10 27.07.2006 -0400, Gabor Grothendieck wrote: If you are willing to write fu2[Var] - 3 instead of fu2(Var) - 3 then this workaround may suffice: fu2 - structure(NA, class = fu2) [-.fu2 - function(x, ..., value) { print(match.call()[[3]]); fu2 } # test fu2[Var] - 3 # prints Var Thank you, Gabor for your response. My example was very reduced, just to show the point, but in the way I would like to use it, probably your solution may be difficult to apply. Seems, I have to accept that I cannot solve it. Thanks again, Heinz On 7/27/06, Heinz Tuechler [EMAIL PROTECTED] wrote: Dear All! If I pass an object to an assignment function I cannot get it's name by deparse(substitute(argument)), but I get *tmp* and I found no way to get the original name, in the example below it should be va1. Is there a way? Thanks, Heinz ## example 'fu1-' - function(var, value) { print(c(name.of.var=deparse(substitute(var} fu1(va1) - 3 name.of.var *tmp* ## desired result: ## name.of.var ##va1 version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status Patched major 2 minor 3.1 year 2006 month 07 day23 svn rev38687 language R version.string Version 2.3.1 Patched (2006-07-23 r38687) __ R-help@stat.math.ethz.ch mailing list 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. __ R-help@stat.math.ethz.ch mailing list 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.