p_tan's blog

勉強日記です。ツッコミ大歓迎

関数に渡された実引数を文字列化する

元ネタ -> r - Quick question: cast function argument as a character string? - Stack Overflow

deparse と substitute を使うと実引数を文字列化できる。

> f <- function(x) deparse(substitute(x))
> f(1)
[1] "1"
> f(x)
[1] "x"
> f(list(x=3))
[1] "list(x = 3)"