看起來%>%
在magrittr封裝不適用於功能load()
。這是我最小的例子來重現我的問題。magrittr封裝中的管道不能用於功能加載()
## Create two example variables and save to tempdir()
a <- 1
b <- 1
save(list = ls(), file = file.path(tempdir(), 'tmp.RData'))
## Remove all variables and load into global environment
# rm(list = ls())
load(file.path(tempdir(), 'tmp.RData'))
ls()
# [1] "a" "b"
# Write the same code with pipe "%>%", but not variable is loaded
# rm(list =ls())
library(magrittr)
tempdir() %>% file.path('tmp.RData') %>% load
ls()
# character(0)
我不明白爲什麼管道不能用於load()
。感謝您的任何建議。
在示例代碼中包含'rm(list = ls())'通常不是好的形式,所以人們不會無意中銷燬他們的工作數據。 – thelatemail 2014-11-21 04:13:38
@thelatemail感謝您的編輯。我通常會打開一個新會話來測試來自stackoverflow和其他人的示例代碼。 – Bangyou 2014-11-21 04:58:56
這可能很聰明。 :-) – thelatemail 2014-11-21 04:59:29