Skip to content

Commit

Permalink
Merge pull request #226 from mrc-ide/i225-filename
Browse files Browse the repository at this point in the history
Allow spaces in filenames
  • Loading branch information
r-ash authored Jun 2, 2021
2 parents 32cabd2 + c085c26 commit 3a7d25f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: odin
Title: ODE Generation and Integration
Version: 1.1.12
Version: 1.1.13
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Thibaut", "Jombart", role = "ctb"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# odin 1.1.13

* Allow spaces in filenames passed to `odin::odin()` (#225)

# odin 1.1.12

* New option `rewrite_constants` (via `odin::odin_options`) which attempts to rewrite all constants in the model code before generation. This can considerably reduce the number of variable lookups (mrc-2252)
Expand Down
2 changes: 1 addition & 1 deletion R/odin_preprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ odin_preprocess <- function(x, type = NULL) {
file <- x
root <- normalizePath(dirname(x))
path <- c(root, normalizePath(getwd()))
base <- chartr("-", "_", tools::file_path_sans_ext(basename(file)))
base <- chartr("- ", "__", tools::file_path_sans_ext(basename(file)))
} else {
file <- NULL
path <- getwd()
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,19 @@ test_that("delay discrete models with defaults are prevented in C", {
})


test_that("Allow spaces in filenames", {
skip_on_cran()
path <- tempfile()
dir.create(path)
on.exit(unlink(path, recursive = TRUE))

filename <- file.path(path, "path with spaces.R")
writeLines(c("initial(x) <- 1", "deriv(x) <- 1"), filename)

mod <- odin(filename, target = "c")
expect_equal(ir_deserialise(odin_ir(mod))$config$base,
"path_with_spaces")
})


unload_dlls()
19 changes: 19 additions & 0 deletions tests/testthat/test-preprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,22 @@ test_that("handle empty input", {
## Previously errored
expect_equal(odin_preprocess_detect(character(0)), "text")
})


test_that("sanitise filenames", {
path <- tempfile()
dir.create(path)
on.exit(unlink(path, recursive = TRUE))

code <- c("initial(x) <- 1", "deriv(x) <- 1")

path_hyphens <- file.path(path, "path-with-hyphens.R")
path_spaces <- file.path(path, "path with spaces.R")
writeLines(code, path_hyphens)
writeLines(code, path_spaces)

expect_equal(odin_preprocess(path_hyphens)$base,
"path_with_hyphens")
expect_equal(odin_preprocess(path_spaces)$base,
"path_with_spaces")
})

0 comments on commit 3a7d25f

Please sign in to comment.