8000 GitHub - cynkra/dir: Use a nested folder structure in your package.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

58 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.

It’s useful if you have a lot of scripts or if you want to turn a non package project into a package.

Set 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 :

# allow nested folders under R/ and patch useful workflow functions
dir::use_dir_package(patch = TRUE)

# use additional folders
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 in the scope of this project 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 (but these won’t be triggered by your existent key bindings).

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 rather than “Build Package Documentation”.

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, here’s a minimal example where you can inspect the file structure, NAMESPACE, .RProfile, .Rbuildignore etc : https://github.com/cynkra/dir/tree/main/inst/dir.example

History

This has been raised on r-devel 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. 53F5 md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0