1

为什么会这样?

library(data.table)
library(plyr)  # For revalue

set.seed(123098)
my_table <- data.table(x=1:10, str=sample(letters[1:4], 10, replace=T))
my_table[, y := 3*x + runif(nrow(my_table))]  # Runs silently

mapping <- c("a"="andrew", "b"="barbarian", "c"="constant", "d"="deft")
my_table[, new_str := revalue(str, replace=mapping)]  # Runs silently

some_condition <- TRUE
if(some_condition) {
    my_table[, y := 3*x + runif(nrow(my_table))]  # Runs silently
    my_table[, new_str := revalue(str, replace=mapping)]  # Why does this print?
}

请注意第二次调用new_str := revalue(str, replace=mapping)-- 在我的机器上,它会打印数据表。在这个无关紧要的小例子中,但我有一个在大型数据表上运行的 R 脚本,我宁愿在日志中没有不需要的打印输出。为什么会发生这种情况,我该如何阻止它?

编辑:如果这有帮助:

$ R --version
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

我的 R 会话:

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plyr_1.8.1       data.table_1.9.4

loaded via a namespace (and not attached):
[1] chron_2.3-45  Rcpp_0.11.3   reshape2_1.4  stringr_0.6.2
4

0 回答 0