存储(几乎)列表中工作区中的所有对象 [英] Store (almost) all objects in workspace in a list
问题描述
比方说,我的工作空间(全局环境)中有许多对象,并且我想将大多数对象存储在列表中.这是一个简化的示例:
Let's say that I have many objects in my workspace (global environment) and I want to store most of those in a list. Here's a simplified example:
# Put some objects in the workspace
A <- 1
B <- 2
C <- 3
我想将对象A和C存储在一个列表中.当然,我可以明确地做到这一点:
I would like to store objects A and C in a list. Of course, I can do that explicitly:
mylist <- list(A,C)
但是,当工作空间中的对象数量很大时,这将变得很麻烦.因此,我想采取不同的方法并尝试以下操作:
However, when the number of objects in the workspace is very large, this would become rather cumbersome. Hence, I would like to do this differently and attempted the following:
mylist <- list(setdiff(ls(),B))
但这显然不是我想要的,因为它仅将对象的名称存储在工作空间中.
But this obviously is not what I want, as it only stores the names of the objects in the workspace.
关于如何执行此操作的任何建议?
Any suggestions on how I can do this?
非常感谢!
推荐答案
另一种选择是使用mget
:
mget(setdiff(ls(),"B"))
这篇关于存储(几乎)列表中工作区中的所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!