2013-09-26 12 views
6

test dizinine dışında veri dosyasını kullanarak testthat: test1.r dosyasındaR - Ben aşağıdakine benzer bir dosya ağacının bir paket test etmek <code>testthat</code> kullanıyorum

. 
    ├── data 
    │   └── testhaplom.out 
    ├── inst 
    │   └── test 
    │    ├── test1.r 
    │    ├── tmp_S7byVksGRI6Q 
    │    │   └── testm.desc 
    │    └── tmp_vBcIkMN1arbn 
    │     ├──testm.bin 
    │     └── testm.desc 
    ├── R 
    │   ├── haplom.r 
    │   └── winIdx.r 
    └── tmp_eUG3Qb0PKuiN 
     └── testhaplom.hap2.desc 

, ben data/testhaplom.out dosyasını kullanmak gerekir Ben test_file(test1.r) yaparsanız, aşağıda hatayı veren inst/test dizine değiştirir ve veri dosyası göremiyorum ancak belirli bir işlev için giriş verileri:

...Error in file(file, "rt") : cannot open the connection 
In addition: Warning message: 
In file(file, "rt") : 
    cannot open file 'data/testhaplom.out': No such file or directory 

cevap

11

için iki çözüm vardır senin Sorun:

Sen göreli yol (../data/testhaplom.out) kullanabilirsiniz:

expect_true(file.exists(file.path("..", "data", "testhaplom.out"))) 

Yoksa veri dizininin yerini almak için system.file kullanabilirsiniz:

expect_true(file.exists(file.path(system.file("data", package="YOUR_R_PACKAGE"), "testhaplom.out"))) 

Ben ikinci çözümü tercih. Her bir platformda doğru yol ayırıcıyı kullanın.

BTW: file.path

İlgili konular