2013-04-02 21 views
5

test_that işlevinin içinde textConnection işlevini kullanmanın neden düzgün çalışmayacağı konusunda herhangi bir fikriniz var mı?<a1> Test</ a1> ile ilgili sorunlar Bağlantılar

yani doğrudan aşağıdaki kodu çalıştırırsanız, her şey çalışıyor harika: Ben yuva bir test_that fonksiyonun bu iç, çalışmıyor ve ben alırsam

boş txt değişken expect_equal gelip
txt <- "" 
con <- textConnection("txt", "w") 
writeLines("test data", con) 
close(con) 

expect_equal(txt, "test data") #Works 

Oysa aramak.

test_that("connection will work", { 

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

    expect_equal(txt, "test data") 
}) #Fails 

Oturum Bilgisi

> 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 

cevap

6

bu deneyin:

test_that("connection will work", { 

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

Ben test_that ayrı ortamında kod değerlendirir gerçeği sorununa bağlı olduğunu benim önsezi gelen var ve sonra textConnection belgelerini denetleme.

+0

+ 1 (neredeyse tamamlandı) yanıtımı sil (mantığım önce textConnection için belgelendirilmiş olsa da) – mnel

+0

Bu hile yaptı! Teşekkürler. –