klmr / box

Write reusable, composable and modular R code
https://klmr.me/box/
MIT License
862 stars 48 forks source link

How to load R script starting with number? #209

Closed MatthieuStigler closed 3 years ago

MatthieuStigler commented 3 years ago

How can one load a R script that starts with a number? I get the message: Error: unexpected input in, or Unable to load module if I try to add backquotes in the path?

Example:

tmp <- tempdir()
script <- paste0(system.file(package = 'box'), "/box/hello_world.r")

dir.create(paste0(tmp, "/box/"))
file.copy(script, paste0(tmp, "/box/1_hello_world.r"), overwrite = TRUE)

box::use(box/1_hello_world)

Thanks!

klmr commented 3 years ago

Module names need to be valid R names, having a number at the beginning is discouraged for that reason.

But backtick-quoting the module name (not the path) works:

box::use(box/`1_hello_world`)
MatthieuStigler commented 3 years ago

great, thanks!