[R] How to coerce an object name to character vector?

MacQueen, Don macqueen1 at llnl.gov
Tue Dec 10 00:34:22 CET 2013


Not tested, but I think you may want this:

do <- function(x,fun, ...) {
  fun <- match.fun(fun)
  obj.name <- deparse(substitute(x))
  assign(obj.name,fun(x, ...))
}



-Don




-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 12/9/13 1:14 PM, "Антон Морковин" <a-morkovin at yandex.ru> wrote:

>
>   For example, I have a numeric vector named "d" (without any
>attributes) and
>   I want to coerce it to character vector "d". Is there any such
>functions? I
>   need  it  to make a function which applies other functions to objects,
>   something like this:
>
>   do<-function(x,fun, ...) {
>   fun<-match.fun(fun)
>   assign(as.character(quote(x)),fun(x, ...))
>   }
>
>   But, of course, quote(x) always return just "x", not the name of
>object.
>
>   Thanks for help!
>
>   ______
>
>   цЁ ц∙ц≈ц│ц√ц┘ц▌ц┴ц┘ц█,
>   ц║.ц║. ц╜ц▐ц▓ц▀ц▐ц≈ц┴ц▌
>______________________________________________
>R-help at r-project.org 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.



More information about the R-help mailing list