我想創(chuàng)建一個函數(shù),其中包括加載我在函數(shù)內(nèi)制作的程序包。簡短示例(無法運行?。簂oadMe <- function(name){
genLib(xxx, libName = name) #make a new library with name "name"
library(name) #load the new library...}這行不通!一段可重復(fù)的代碼說明了我的主要問題:library(ggplot) #this works fineload.this <- "ggplot"library(load.this) #I want this to load ggplot!我知道問題在于,library()并require()以一個尚不存在的對象名稱作為參數(shù)。我已經(jīng)試過包裝我的字符串,parse(),deparse(),substitute(),expression(),quote(),等等等等,這些都返回了同樣的問題:library(load.this)# Error in library(loadss) : there is no package called 'loadss'library(deparse(load.this))# Error in library(deparse(loadss)) : 'package' must be of length 1有沒有辦法做到這一點?
3 回答

萬千封印
TA貢獻1891條經(jīng)驗 獲得超3個贊
為什么要避免parse
?substitute
在這種情況下,您如何獲得相同的結(jié)果?我正在考慮一種情況,當我不知道先驗地應(yīng)該加載哪個庫時,盡管我可能將其作為文本字符串存儲。
- 3 回答
- 0 關(guān)注
- 646 瀏覽
添加回答
舉報
0/150
提交
取消