【发布时间】:2018-03-29 13:13:02
【问题描述】:
我正在尝试修改 save() 函数,以便将源自对象的脚本存储为对象的属性。
s = function(object, filepath, original.script.name){
#modified save() function
#stores the name of the script from which the object originates as an attribute, then saves as normal
attr(object, "original.script") = original.script.name
save(object, file = filepath)
}
示例:
testob = 1:10
testob
# [1] 1 2 3 4 5 6 7 8 9 10
s(testob, filepath = "rotation1scripts_v4/saved.objects/testob", "this.is.the.name")
load(file = "rotation1scripts_v4/saved.objects/testob")
testob
# [1] 1 2 3 4 5 6 7 8 9 10
attributes(testob)
# NULL
进一步调查,似乎没有将对象加载到环境中:
testob2 = 1:5
testob2
# [1] 1 2 3 4 5
s(testob2, "rotation1scripts_v4/saved.objects/testob2", "this.is.the.name")
rm(testob2)
load(file = "rotation1scripts_v4/saved.objects/testob2")
testob2
# Error: object 'testob2' not found
为什么它不起作用?
【问题讨论】:
-
寻求帮助时,您应该包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出。你究竟是如何调用这个函数的?你如何验证属性没有被保留?
-
嗨 MrFlick,例如查看更新后的帖子。谢谢
标签: r object attributes save