Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working directory when preparing package for testing in test() #640

Closed
krlmlr opened this issue Nov 7, 2014 · 6 comments · Fixed by #641
Closed

Working directory when preparing package for testing in test() #640

krlmlr opened this issue Nov 7, 2014 · 6 comments · Fixed by #641

Comments

@krlmlr
Copy link
Member

krlmlr commented Nov 7, 2014

When testing a package using devtools::test(), the current working directory for executing the package's code ("installing" the package into a temporary environment) seems to be the R subdirectory of the package, whereas it's the package's root directory when using devtools::check().

Test package: https://github.com/krlmlr/test.getwd

Output with devtools::test() (copied from RStudio's console):

In package: /home/muelleki/git/R/test.getwd/R

Output with devtools::check(): https://github.com/krlmlr/test.getwd/blob/master/test.getwd.Rcheck/00install.out#L4

EDIT: It's the same with devtools::document().

Is this by design? Otherwise I'd like to take a look at this, so that the CWD is always the package's root.

This is important when the package wants to access stuff in inst/ during installation: This seems to work with R, but doesn't when testing using devtools::test().

@hadley
Copy link
Member

hadley commented Nov 7, 2014

I think that's an accident - it should match R CMD check as closely as possible.

But I think you should always be able to use system.file() to get files in inst/

@wch
Copy link
Member

wch commented Nov 7, 2014

Are you using the version of devtools that lets you call test() and other functions from any subdirectory, and is your current working directory the R/ subdirectory? I believe devtools::test() just runs in the current working dir.

@krlmlr
Copy link
Member Author

krlmlr commented Nov 7, 2014

@hadley: Thanks -- system.file seems to return the correct path. However, this means that I need to figure out the name of the package that is being installed -- getNamespaceName(parent.frame()) didn't produce useful results for the test() and document() cases but works for R CMD check and R CMD INSTALL. (I'll take a look at this issue as well -- according to getNamespaceInfo it seems that we need to place an object named .__NAMESPACE__. in the package's environment.) I have updated the test package.

@wch: No, CWD is package root when running those tests.

@gaborcsardi
Copy link
Member

Btw. packageName() is supposed to give you the name of the package is it called from, but I am actually not sure if it works from devtools.

@krlmlr
Copy link
Member Author

krlmlr commented Nov 7, 2014

Code is explicitly loaded with R/ as current directory: https://github.com/hadley/devtools/blob/master/R/load-code.r#L26.

@gaborcsardi: Thanks, didn't know that. This function expects an object named .packageName in the environment. Actually, both packageName() and getNamespaceName(...) seem to work from devtools -- not sure why I assumed otherwise.

@lock
Copy link

lock bot commented Sep 18, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Sep 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants