Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

krlmlr/pkg.subdir.test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pkg.subdir.test

Placing source files for R packages in subdirectories of R/.

Directory structure

dir(".", recursive = TRUE)
#> [1] "DESCRIPTION"           "NAMESPACE"             "pkg.subdir.test.Rproj"
#> [4] "R/0.R"                 "R/a/1.R"               "R/b/2.R"              
#> [7] "R/zzz.R"               "README.md"             "README.Rmd"

Code to load files from subdirectories

## Contents of file R/zzz.R
dummy <- function() {}

first_level_files <- dir("R", full.names = TRUE)
dirs <- first_level_files[file.info(first_level_files)$isdir]
source_files <- dir(first_level_files, recursive = TRUE, full.names = TRUE)

for (file in source_files) sys.source(file, environment(dummy))

Result

devtools::load_all()
#> Loading pkg.subdir.test
f
#> function(x) "defined in 0.R"
#> <environment: namespace:pkg.subdir.test>
a
#> function(x) "defined in 1.R"
#> <environment: namespace:pkg.subdir.test>
b
#> function(y) "defined in 2.R"
#> <environment: namespace:pkg.subdir.test>
  • Functions have the correct environment
  • roxygen2 directives are not (yet) picked up correctly

About

Source files in subdirectories of R/

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages