Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:53:27+00:00 2026-06-11T08:53:27+00:00

I am using the testthat package to test an R package that is within

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:53:28+00:00Added an answer on June 11, 2026 at 8:53 am

    As it says in R-exts

    The directory tests is copied to the check area, and the tests are run with the copy as the working directory and with R_LIBS set to ensure that the copy of the package installed during testing will be found by library(pkg_name).

    By default, the check directory is created in the current directory. Thus when running R CMD check from ~/MyRepo, the tests directory is copied to ~/MyRepo/MyRpkg.Rcheck/tests and hence

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

    is interpreted as

    check.script <- readLines("~/MyRepo/Scripts/myscript.sh")[1]
    

    as required. However starting from ~/ would imply

    check.script <- readLines("~/Scripts/myscript.sh")[1]
    

    which isn’t what you want. A work-around is to specify the directory in which the check directory is created, i.e.

    R CMD check -o MyRepo MyRepo/MyRpkg
    

    so that the copied tests directory has the same “grandparent” as the original tests directory.

    Still, I wonder why the file must be external to the package. If you want to use the file in the package tests, it would make sense to include the file in the package. You could create an inst directory and put the Scripts directory in there, so that the Scripts directory will be copied to the package directory on installation and then

    check.script <- readLines("../foo/Scripts/myscript.sh")[1]
    

    could be used inside the test script, since the package is installed in MyRpkg.Rcheck/foo during R CMD check. Alternatively you could create an exec directory and put the script file in there, then

    check.script <- readLines("../foo/exec/myscript.sh")[1]
    

    would work. As both of these solutions only need to find the package installed during testing it wouldn’t matter where you ran R CMD check from. See Package subdirectories and Non-R scripts in packages for more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHPUnit test that's using a Doctrine2 custom repository and Doctrine Fixtures.
I have a test that exercises a custom Swing component using java.awt.Robot. I'd like
I am using the built in test framework in VS2008 and I would like
How can I test that I'm being redirected to an external location using Cucumber?
Using RSpec, I want to test that certain methods are called within a method.
Using PHP how can I accurately test that a remote website supports the If-Modified-Since
Using Java, how can I test that a URL is contactable, and returns a
Scope: Using Google Test and OpenCV. I'd like to test that my Vec3f equals
I'm using Python's unittest. I'd like to write a test that ensures a certain
I'm working on developing an R package, using devtools, testthat, and roxygen2. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.