Skip to content
/ dir Public

Use a nested folder structure in your package.

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

cynkra/dir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dir

{dir} allows you to store your code in a nested folder structure, rather than solely in the “R” folder, without any code duplication.

Set it up your project with one command and work as usual, just with as many folders as you like.

{dir} won’t be needed by the end users of your package, you don’t even need it in your Suggests dependencies.

Your package won’t violate any CRAN policy. See further below to understand how it’s possible.

Installation

Install with:

pak::pak("cynkra/dir")

Package Setup

To set up your package to use it with ‘dir’ we recommend the following :

dir::use_dir_package("any_folder_in_your_repo", "maybe_another", patch = TRUE)

This will set your project’s .RProfile so the multi folder thing just works.

Note that patch = TRUE means we modify some functions from ‘usethis’ and ‘devtools’. They still work as they did but now support flexible folder structures. The default patch = FALSE is less invasive, it doesn’t touch those but places shims in a "dir-overrides" environment on the search path.

For a better experience if you use RStudio we advise that you remap Ctrl+Shift+D to call devtools::document() outside of the build pane, because we can’t patch the build pane and the output of devtools::document() is usually terse enough anyway.

For this go to Tools / Modify Keyboard Shortcuts and use the “Document a package” addin.

How does it work?

dir::use_dir_package() sets a hook so any time it’s loaded (by you, not your users) :

  • We make sure your additional folders are added to “.Rbuidignore”
  • We load the code from your added folders into the sysdata.rda file in the R folder
  • We load the objects into the session
  • We patch (if you opt in) the ‘usethis’ and ‘devtools’ function that didn’t play well with the flexible folder structure.

Files and folders starting with “_” or “.” in your added folders will be ignored by the process.

So your code can be outside of the R folder but all the objects are inside, and that makes it CRAN compliant.

Do you have an example ?

Sure, there you go!

History

This has been raise on r-devel multiple times multiple times but little interest has been shown to implement the feature, so here we are.

Other efforts

These packages implement other solutions to the problem of working with multiple code folders:

About

Use a nested folder structure in your package.

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages