143

変数名を持つ次のデータ フレームがあります"foo"

 > foo <-c(3,4);

私がやりたいことは"foo"、文字列に変換することです。そのため、関数で別の追加の変数を再作成する必要はありません。

   output <- myfunc(foo)
   myfunc <- function(v1) {
     # do something with v1
     # so that it prints "FOO" when 
     # this function is called 
     #
     # instead of the values (3,4)
     return ()
   }
4

1 に答える 1

283

とを使用deparsesubstituteて、関数の引数の名前を取得できます。

myfunc <- function(v1) {
  deparse(substitute(v1))
}

myfunc(foo)
[1] "foo"
于 2013-01-29T07:37:36.977 に答える