Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么以下自定义对象功能不起作用?
objects0 <- function(find_term) { objects(pattern=glob2rx(paste0("*",find_term,"*"))) } txt1 <- 100 tt <- 200 > objects0('txt') character(0)
但是当我写
objects(pattern=glob2rx(paste0("*",'txt',"*")))
它工作得很好。
您需要指定查找对象的环境。
添加参数envir=parent.frame()调用objects:
envir=parent.frame()
objects
objects0 <- function(find_term)objects(pattern=glob2rx(paste0("*",find_term,"*")), envir=parent.frame())
也许更好的方法是添加envir=globalenv()以确保始终在全局环境中完成搜索。
envir=globalenv()