![](/img/trans.png)
[英]R: Get function name called with package::function as string in R
[英]Get a function from a string of the form “package::function”
已經討論過如何從字符串中獲取變量。 實際上, get
使用data.table
函數: get("data.table")
返回data.table
。 然而,
> get("data.table::data.table")
Error in get("data.table::data.table") :
object 'data.table::data.table' not found
有沒有辦法保留對包名稱的引用? 即,我不想簡單地對“::”進行拆分並得到字符串的后半部分。
您可以使用envir
參數從命名空間中獲取函數。
get("data.table", envir = getNamespace("data.table"))
或者更簡單地說@joran注釋,可以使用getFromNamespace()
。
getFromNamespace("data.table", "data.table")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.