Can I accesss an external file when testing an R package?

Posted by Abe on Stack Overflow See other posts from Stack Overflow or by Abe
Published on 2012-09-05T23:00:07Z Indexed on 2012/09/13 21:38 UTC
Read the original article Hit count: 132

Filed under:
|
|

I am using the testthat package to test an R package that is within a larger repository. I would like to test the contents of a file outside of the R package.

Can I reference a file that is located outside of an R package while testing?

What I have tried

A reproducible example can be downloaded as MyRepo.tar.gz

My repository is called "myRepo", and it includes an R package, "myRpkg" and a folder full of miscellaneous scripts

~/MyRepo/
~/MyRepo/MyRpkg
~/MyRepo/Scripts

The tests in "MyRpkg" are in the /tests/ folder

~/myRepo/myRpkg/tests/test.myscript.R

And I want to be able to test a file in the Scripts folder:

~/MyRepo/Scripts/myscript.sh

I would like to read the script to test the contents of the first line doing something like this:

  check.script <- readLines("../../../Scripts/myscript.sh")[1]
  expect_true(grepl("echo", check.script))

This works fine if I start from the MyRepo directory:

cd ~/MyRepo
R CMD check MyRpkg

But if I move to another directory, it fails:

cd
R CMD check MyRepo/MyRpkg

© Stack Overflow or respective owner

Related posts about r

    Related posts about bash