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

Export and document check_dir #985

Closed
jrounds opened this Issue Nov 23, 2015 · 7 comments

Comments

Projects
None yet
4 participants
@jrounds

jrounds commented Nov 23, 2015

Short version:
Can you export devtools:::check_dir and rename it to devtools::package_root, and give it a default parameter of ".".

Long version:

Been using devtools at work to develop analysis packages. One common thing I do is put extra scripts in what is a package directory. These scripts usually need some awareness of their relative location to package root, but it occurred to me that devtools::load_all() has an ability to find package root no matter what the working directory is as long as it is a sub-directory of the package. I inspected the source and noted it all came down to devtools::check_dir("."), and I thought this is wonderful...

Shouldn't everything we code use that as a root directory? This way a source file never needs to know where it is relative to the root of a package. For example I was modifying a colleagues data structure and wanted to save it in package_root/data. A way to do that in devtools is:

save(tcga_ovarian_pepdata_bp, file = file.path(devtools:::check_dir("."), "data","ModifiedOvarianPepdataBP.Rdata"))

Now no matter where this script ends up in any sub-directory of the package the object will always be saved in package_root/data. I can put this save two nested directories deep and the script doesn't need to know. That is cool! But, it isn't exported and has a cryptic name.

@hadley hadley closed this in 4abed65 Jan 12, 2016

@hadley

This comment has been minimized.

Member

hadley commented Jan 12, 2016

Nice idea!

I made it work so you can do:

save(tcga_ovarian_pepdata_bp, file = package_path("data","ModifiedOvarianPepdataBP.Rdata"))
@hadley

This comment has been minimized.

Member

hadley commented Jan 12, 2016

BTW in this case you'd probably be better off using saveRDS().

@gaborcsardi

This comment has been minimized.

Member

gaborcsardi commented Jan 12, 2016

👍

@jrounds

This comment has been minimized.

jrounds commented Jan 12, 2016

Thanks!

@jennybc

This comment has been minimized.

Member

jennybc commented Jan 12, 2016

This way a source file never needs to know where it is relative to the root of a package.

Slightly off-topic but .. if only something this sane could be used in an RStudio project that isn't an R package .... rstudioapi::project_file()?

@hadley

This comment has been minimized.

Member

hadley commented Jan 13, 2016

@jennybc I don't see why not. File an issue over there?

@lock

This comment has been minimized.

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.