我想說明已分配給函式中引數的變數。函式更復雜,但下面是一個示例場景,我希望函式回傳變數的名稱:x
例如
x <- 3
my_function <- function(arg1) {print(arg1)}
其中:my_function(x)將回傳x
并且:my_function(y)將回傳y
這可能嗎?
uj5u.com熱心網友回復:
用于substitute回傳一個symbol物件。如果我們用deparseon包裝substitute,它會回傳一個character
my_function <- function(arg1) substitute(arg1)
-測驗
> my_function(x)
x
> my_function(y)
y
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/435612.html
