R 测试连接的问题

R 测试连接的问题,r,testthat,R,Testthat,有人知道为什么在测试中使用textConnection会导致功能无法正常运行吗 i、 e.如果我直接运行以下代码,一切都很好: txt <- "" con <- textConnection("txt", "w") writeLines("test data", con) close(con) expect_equal(txt, "test data") #Works 会话信息 > sessionInfo() R version 2.15.2 (2012-10-26)

有人知道为什么在
测试中使用
textConnection
会导致功能无法正常运行吗

i、 e.如果我直接运行以下代码,一切都很好:

txt <- ""
con <- textConnection("txt", "w")  
writeLines("test data", con)
close(con)

expect_equal(txt, "test data")  #Works
会话信息

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
  [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

other attached packages:
  [1] testthat_0.7  RODProt_0.1.1 rjson_0.2.12 

loaded via a namespace (and not attached):
  [1] evaluate_0.4.2 plyr_1.8       stringr_0.6.1  tools_2.15.2 
试试这个:

test_that("connection will work", {

  txt <- ""
  con <- textConnection("txt", "w",local = TRUE)  
  writeLines("test data", con)
  close(con)
  expect_equal(txt, "test data")  
})
测试(“连接将正常工作”{
txt+1删除我的(几乎完成)响应(尽管我的逻辑首先检查了文档中的
textConnection
test_that("connection will work", {

  txt <- ""
  con <- textConnection("txt", "w",local = TRUE)  
  writeLines("test data", con)
  close(con)
  expect_equal(txt, "test data")  
})