获取函数的确切输入文本

Pat*_* Li 1 string r

我想获得函数参数的确切输入文本并在输出中打印出来.例如,以下函数将采用整数向量并返回其正方形.

> my_func <- function(x) {
+     print(paste0("The square of ", toString(x), " is: ", toString(x^2)))
+ }
> my_func(1:4)
[1] "The square of 1, 2, 3, 4 is: 1, 4, 9, 16"
Run Code Online (Sandbox Code Playgroud)

我想要的输出是

The square of "1:4" is: 1, 4, 9, 16
Run Code Online (Sandbox Code Playgroud)

其中1:4正好是函数的输入文本.

Ony*_*mbu 5

my_func <- function(x) {
    print(paste0("The square of ", deparse(x), " is: ", toString(x^2)))
}
Run Code Online (Sandbox Code Playgroud)