Skip to content

Commit 8a69115

Browse files
authored
Merge pull request #343 from stan-dev/various_minor_fixes
Minor fixes and version 0.2.0
2 parents baed002 + 18cda03 commit 8a69115

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1680
-1566
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: cmdstanr
22
Title: R Interface to 'CmdStan'
3-
Version: 0.1.3
4-
Date: 2020-08-21
3+
Version: 0.2.0
4+
Date: 2020-11-12
55
Authors@R:
66
c(person(given = "Jonah", family = "Gabry", role = c("aut", "cre"),
77
email = "[email protected]"),

NEWS.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Items for next tagged release
1+
# cmdstanr 0.2.0
22

33
### Bug fixes
44

@@ -20,10 +20,12 @@ in fitting methods. (#281, #294)
2020

2121
* Fix issue where names of generated files could clash. (#326, #328)
2222

23-
* Fix missing `include_paths` in `$syntax_check()`. (#335)
23+
* Fix missing `include_paths` in `$syntax_check()`. (#335, @mike-lawrence)
2424

2525
### New features
2626

27+
* CSV reading is now faster by using `data.table::fread()`. (#318)
28+
2729
* `install_cmdstan()` gains argument `version` for specifying which version of
2830
CmdStan to install. (#300, #308)
2931

@@ -35,7 +37,7 @@ specifying custom chain IDs. (#319)
3537

3638
* Added support for the `sig_figs` argument in CmdStan versions 2.25 and above. (#327)
3739

38-
* CSV reading is now faster by using `data.table::fread()`. (#318)
40+
* Added checks if the user has the necessary permissions in the RTools and temporary folders. (#343)
3941

4042
# cmdstanr 0.1.3
4143

R/install.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,16 @@ build_status_ok <- function(process_log, quiet = FALSE) {
427427
}
428428

429429
install_mingw32_make <- function(quiet = FALSE) {
430+
rtools_usr_bin <- file.path(Sys.getenv("RTOOLS40_HOME"), "usr", "bin")
431+
if (!checkmate::test_directory(rtools_usr_bin, access = "w")) {
432+
warning("No write permissions in the RTools folder. This might prevent installing mingw32-make.",
433+
" Consider changing permissions or reinstalling RTools in a different folder.", call. = FALSE)
434+
}
430435
if (!quiet) message("Installing mingw32-make and writing RTools path to ~/.Renviron ...")
431436
processx::run(
432437
"pacman",
433438
args = c("-Syu", "mingw-w64-x86_64-make","--noconfirm"),
434-
wd = file.path(Sys.getenv("RTOOLS40_HOME"), "usr", "bin"),
439+
wd = rtools_usr_bin,
435440
error_on_status = TRUE
436441
)
437442
write('PATH="${RTOOLS40_HOME}\\usr\\bin;${RTOOLS40_HOME}\\mingw64\\bin;${PATH}"', file = "~/.Renviron", append = TRUE)
@@ -595,6 +600,9 @@ check_cmdstan_toolchain <- function(fix = FALSE, quiet = FALSE) {
595600
check_unix_make()
596601
check_unix_cpp_compiler()
597602
}
603+
if (!checkmate::test_directory(dirname(tempdir()), access = "w")) {
604+
stop("No write permissions to the temporary folder! Please change the permissions or location of the temporary folder.", call. = FALSE)
605+
}
598606
if (!quiet) {
599607
message("The CmdStan toolchain is setup properly!")
600608
}

R/model.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ CmdStanModel <- R6::R6Class(
201201
private$stan_file_ <- absolute_path(stan_file)
202202

203203
args <- list(...)
204+
check_stanc_options(args$stanc_options)
204205
private$precompile_cpp_options_ <- args$cpp_options %||% list()
205206
private$precompile_stanc_options_ <- args$stanc_options %||% list()
206207
private$precompile_include_paths_ <- args$include_paths
@@ -366,6 +367,7 @@ compile_method <- function(quiet = TRUE,
366367
if (length(stanc_options) == 0 && !is.null(private$precompile_stanc_options_)) {
367368
stanc_options <- private$precompile_stanc_options_
368369
}
370+
check_stanc_options(stanc_options)
369371
if (is.null(include_paths) && !is.null(private$precompile_include_paths_)) {
370372
include_paths <- private$precompile_include_paths_
371373
}
@@ -465,19 +467,18 @@ compile_method <- function(quiet = TRUE,
465467
if (is.null(stanc_options[["name"]])) {
466468
stanc_options[["name"]] <- model_name
467469
}
468-
stanc_built_options = c()
470+
stanc_built_options <- c()
469471
for (i in seq_len(length(stanc_options))) {
470472
option_name <- names(stanc_options)[i]
471473
if (isTRUE(as.logical(stanc_options[[i]]))) {
472-
stanc_built_options = c(stanc_built_options, paste0("--", option_name))
474+
stanc_built_options <- c(stanc_built_options, paste0("--", option_name))
475+
} else if (is.null(option_name) || !nzchar(option_name)) {
476+
stanc_built_options <- c(stanc_built_options, paste0("--", stanc_options[[i]]))
473477
} else {
474-
stanc_built_options = c(stanc_built_options, paste0("--", option_name, "=", "'", stanc_options[[i]], "'"))
478+
stanc_built_options <- c(stanc_built_options, paste0("--", option_name, "=", "'", stanc_options[[i]], "'"))
475479
}
476480
}
477481
stancflags_val <- paste0("STANCFLAGS += ", stancflags_val, paste0(stanc_built_options, collapse = " "))
478-
if (cmdstan_version() < "2.24") {
479-
prepare_precompiled(cpp_options, quiet)
480-
}
481482
run_log <- processx::run(
482483
command = make_cmd(),
483484
args = c(tmp_exe,

R/utils.R

Lines changed: 18 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -208,64 +208,22 @@ cpp_options_to_compile_flags <- function(cpp_options) {
208208
paste0(cpp_built_options, collapse = " ")
209209
}
210210

211-
prepare_precompiled <- function(cpp_options = list(), quiet = FALSE) {
212-
flags <- NULL
213-
if (!is.null(cpp_options$stan_threads)) {
214-
flags <- c(flags, "threads")
215-
}
216-
if (!is.null(cpp_options$stan_mpi)) {
217-
flags <- c(flags, "mpi")
218-
}
219-
if (!is.null(cpp_options$stan_opencl)) {
220-
flags <- c(flags, "opencl")
221-
}
222-
if (is.null(flags)) {
223-
flags <- "noflags"
224-
} else {
225-
flags <- paste0(flags, collapse = "_")
226-
}
227-
main_path_w_flags <- file.path(cmdstan_path(), "src", "cmdstan", paste0("main_", flags, ".o"))
228-
main_path_o <- file.path(cmdstan_path(), "src", "cmdstan", "main.o")
229-
model_header_path_w_flags <- file.path(cmdstan_path(), "stan", "src", "stan", "model", paste0("model_header_", flags, ".hpp.gch"))
230-
model_header_path_gch <- file.path(cmdstan_path(), "stan", "src", "stan", "model", "model_header.hpp.gch")
231-
if (file.exists(model_header_path_gch)) {
232-
model_header_gch_used <- TRUE
233-
} else {
234-
model_header_gch_used <- FALSE
235-
}
236-
if (!file.exists(main_path_w_flags)) {
237-
message(
238-
"Compiling the main object file and precompiled headers (may take up to a few minutes). ",
239-
"This is only necessary the first time a model is compiled after installation or when ",
240-
"threading, MPI or OpenCL are used for the first time."
241-
)
242-
clean_compile_helper_files()
243-
run_log <- processx::run(
244-
command = make_cmd(),
245-
args = c(cpp_options_to_compile_flags(cpp_options),
246-
main_path_o),
247-
wd = cmdstan_path(),
248-
echo_cmd = !quiet,
249-
echo = !quiet,
250-
spinner = quiet,
251-
stderr_line_callback = function(x,p) { if (!quiet) message(x) },
252-
error_on_status = TRUE
253-
)
254-
file.copy(main_path_o, main_path_w_flags)
255-
if (model_header_gch_used) {
256-
run_log <- processx::run(
257-
command = make_cmd(),
258-
args = c(cpp_options_to_compile_flags(cpp_options),
259-
file.path("stan", "src", "stan", "model", "model_header.hpp.gch")),
260-
wd = cmdstan_path(),
261-
echo_cmd = !quiet,
262-
echo = !quiet,
263-
spinner = quiet,
264-
stderr_line_callback = function(x,p) { if (!quiet) message(x) },
265-
error_on_status = TRUE
266-
)
267-
file.copy(model_header_path_gch, model_header_path_w_flags)
211+
check_stanc_options <- function(stanc_options) {
212+
i <- 1
213+
names <- names(stanc_options)
214+
for (s in stanc_options){
215+
if (!is.null(names[i]) && nzchar(names[i])) {
216+
name <- names[i]
217+
} else {
218+
name <- s
268219
}
220+
if (startsWith(name, "--")) {
221+
stop("No leading hyphens allowed in stanc options (", name, "). ",
222+
"Use options without leading hyphens, like for example ",
223+
"`stanc_options = list('allow-undefined')`",
224+
call. = FALSE)
225+
}
226+
i <- i + 1
269227
}
270228
}
271229

@@ -288,7 +246,8 @@ num_threads <- function() {
288246
#' @export
289247
#' @param num_threads (positive integer) The number of threads to set.
290248
set_num_threads <- function(num_threads) {
291-
stop("Please use the 'threads_per_chain' argument in the $sample() method instead of set_num_threads().")
249+
stop("Please use the 'threads_per_chain' argument in the $sample() method instead of set_num_threads().",
250+
call. = FALSE)
292251
}
293252

294253
check_divergences <- function(data_csv) {
@@ -381,3 +340,4 @@ variable_dims <- function(variable_names = NULL) {
381340
}
382341
dims
383342
}
343+

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOpt
4141
or you can install the latest development version from GitHub:
4242

4343
```r
44-
# install.packages("devtools")
45-
devtools::install_github("stan-dev/cmdstanr")
44+
# install.packages("remotes")
45+
remotes::install_github("stan-dev/cmdstanr")
4646
```
4747

4848
### Contributing

docs/404.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE-text.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)