Skip to content

Commit

Permalink
version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau authored and cran-robot committed Jan 10, 2024
1 parent b0eb19a commit 084a6a9
Show file tree
Hide file tree
Showing 53 changed files with 707 additions and 795 deletions.
29 changes: 11 additions & 18 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ Description: Similar to 'rstantools' for 'rstan',
The models compile once during installation,
the executables live inside the file systems of their respective packages,
and users have the full power and convenience of
'cmdstanr' without any additional compilation.
This approach saves time, allows R package developers
to migrate from 'rstan' to the more modern
'cmdstanr', and fits well with centrally maintained
R installations where users have trouble installing
their own packages, diagnosing compilation errors,
and setting environment variables.
'cmdstanr' without any additional compilation after package installation.
This approach saves time and helps R package developers
migrate from 'rstan' to the more modern 'cmdstanr'.
Packages 'rstantools', 'cmdstanr', 'stannis', and
'stanapi' are similar Stan clients with different objectives.
Version: 0.0.2
Version: 0.2.0
License: MIT + file LICENSE
URL: https://wlandau.github.io/instantiate/,
https://github.com/wlandau/instantiate
Expand All @@ -25,29 +21,26 @@ Authors@R: c(
given = c("William", "Michael"),
family = "Landau",
role = c("aut", "cre"),
email = "will.landau@gmail.com",
email = "will.landau.oss@gmail.com",
comment = c(ORCID = "0000-0003-1878-3253")
),
person(
family = "Eli Lilly and Company",
role = c("cph", "fnd")
))
Depends: R (>= 4.0.0)
Imports: fs, pkglite, rlang, utils
Suggests: cmdstanr, knitr (>= 1.30), markdown (>= 1.1), rmarkdown (>=
2.4), testthat (>= 3.0.0), withr
Additional_repositories: https://mc-stan.org/r-packages/
SystemRequirements: CmdStan
(https://mc-stan.org/users/interfaces/cmdstan)
Imports: fs, rlang, utils
Suggests: knitr (>= 1.30), markdown (>= 1.1), rmarkdown (>= 2.4),
testthat (>= 3.0.0), withr
Encoding: UTF-8
Language: en-US
Config/testthat/edition: 3
RoxygenNote: 7.2.3
NeedsCompilation: yes
Packaged: 2023-08-08 19:24:05 UTC; C240390
Packaged: 2024-01-09 15:40:24 UTC; C240390
Author: William Michael Landau [aut, cre]
(<https://orcid.org/0000-0003-1878-3253>),
Eli Lilly and Company [cph, fnd]
Maintainer: William Michael Landau <will.landau@gmail.com>
Maintainer: William Michael Landau <will.landau.oss@gmail.com>
Repository: CRAN
Date/Publication: 2023-08-11 07:40:02 UTC
Date/Publication: 2024-01-09 22:33:21 UTC
86 changes: 48 additions & 38 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
fa20e0a4cfdf477151eaca4737b16213 *DESCRIPTION
6b436f30d1503fe3f4bf5a01cc0a7acc *DESCRIPTION
251996587bac8db01533ad7011f0c4f5 *LICENSE
78beea0ac35e1ea45cbc06342c68a831 *NAMESPACE
c918c770d1fcf17efabb500963f28d4a *NEWS.md
4096c17c1368aaf04299111dba9a96d1 *R/stan_cmdstan_exists.R
bdd22a615487885750afa9e366537017 *R/stan_cmdstan_path.R
b35a2c9af71f3e548714f2bbff69ff13 *R/stan_cmdstan_version.R
d9c83f68c35851356f82216be6508538 *R/stan_package.R
500edf9a014381847bf9312201ba9bbb *NAMESPACE
6ac387c4e85d9cc5f9088f1d61d69660 *NEWS.md
2bef7698ac8415315bc135a49e578fd7 *R/stan_cmdstan_exists.R
fbbc28ba2a7f1db7e2cbfdd60ded45ea *R/stan_cmdstan_path.R
41567ca03c5d51725a8df8671a85df29 *R/stan_cmdstan_version.R
f1089690180d58f2274a2c019b7eefde *R/stan_package.R
5e5c02177f5a1f2dbddda85f123e2bd5 *R/stan_package_clean.R
b4a3777898ff660f516e6e1d112ef2ea *R/stan_package_compile.R
f65c030d2a92ccc776fafdf691332f1e *R/stan_package_configure.R
86296963e35b066d4237039fd1d3bbbb *R/stan_package_create.R
23b72f28c1b926390bc70c29833de8cc *R/stan_package_model.R
00b795b242ac66d2a70425dbe8e712df *R/stan_package_model_files.R
8d1c9c73efaf366b5d6bdfc37cc4b150 *R/utils_assert.R
a5d1fcd86602dd91bbc3de47e172e2f2 *R/utils_cmdstan.R
fea8c1c0b7a797b3cefb80464f6c3eed *R/stan_package_compile.R
5fb7e19eb46ea6eccad90776e9062d35 *R/stan_package_configure.R
5910f1ddb7d6b74b26f5d053fd49b7ab *R/stan_package_create.R
5a18040af8f27b9d1863d4b06ec872a0 *R/stan_package_model.R
2d07bee7c202862603b17c252f572b9e *R/stan_package_model_files.R
8febf351efa09a0ee3afe6ea49e7a333 *R/utils_assert.R
ddfbc90c3af7635bf90b25c40afeee27 *R/utils_cmdstan.R
c26a302f5f40a8420c2ea010a4826796 *R/utils_logic.R
8c719b65887d307d9652cc33c8a624bc *R/utils_os.R
7ed33c5af77cea2896552b8aa69f1294 *cleanup
105248ba9946c1c8a8fe16b1e732800c *cleanup.win
da3517530af446547973dd5067ca8cad *configure
772af69d3c9d95879dcee8632f57047a *configure.win
00d80b44380400a761ef43354611cdf2 *cleanup
246c183dd8d2b2fdf321c4d26136f7e2 *cleanup.win
c9e3f54962da09c419801231e6d93af6 *configure
1a97403ae758a1a21f2df847f3b8dbad *configure.win
2f9b7e68130c000bb936834add088476 *inst/WORDLIST
e27087597cd18e4c65d71340c9dd5957 *inst/cmdstan.R
036cd7835a502c1dd418ec3042f468dc *inst/configuration/cleanup
935003f51ab2ad33734bff47d541e742 *inst/configuration/cleanup.win
23d93b95a5bc3065db71d3de7dd7af97 *inst/configuration/configure
c790e59374717b5917d020ac8d436bca *inst/configuration/configure.win
bd063fc25cbff48eaf6140e68bb4cf46 *inst/example.txt
3b7617e15d7df93897d64abaca719ff8 *man/instantiate-package.Rd
e2a3585fd67ec2c0c67adb74f3d75310 *man/stan_cmdstan_exists.Rd
4300156c33795172f4b80614bcafda6c *man/stan_cmdstan_path.Rd
c2c394ef1e205dc5de6c97c1600a07f6 *man/stan_cmdstan_version.Rd
5e6feb7c96b3fa5cbcb363edc964635f *man/stan_package_clean.Rd
e9fb2091074200681c15b03cbee31780 *man/stan_package_compile.Rd
adefdcdb7dce555b8328bfd35ba61cd7 *man/stan_package_configure.Rd
4f52065b21254d58b115bd70fdacee30 *inst/configuration/cleanup
e2e64968e7947d94a4ab5c5effe6e918 *inst/configuration/cleanup.win
9919e70bfb6fb150ab345f949e40fcaa *inst/configuration/install.libs.R
ad95a0ead03f3750c14185d1208ea057 *inst/example/DESCRIPTION
637acb3d8af3a4f654eaccfdeb0bbba1 *inst/example/NAMESPACE
b30634283cd20ed38b6245815bb00dd1 *inst/example/NOTICE
4341f75ee5eb85b991fe201e35ba2f18 *inst/example/R/model.R
5067a3c1eb447626b85d2372ab34e59f *inst/example/R/package.R
dd674e027f8a360bd2cde6ac98fad66f *inst/example/github/workflows/check.yaml
67b9baa59a66acd7d4ef10280d1617db *inst/example/gitignore
efcd2d3a39a16be5c2796bac59ed06ba *inst/example/man/example-package.Rd
93cd10609b8ddf6d25b150b746970730 *inst/example/man/run_bernoulli_model.Rd
f13db28d34167ce65e17c6c733508fe4 *inst/example/rbuildignore
582f942393b9f2ed2560e1a24541fa7b *inst/example/src/stan/bernoulli.stan
867227809d4b31babcb17c9c70bf7e14 *man/instantiate-package.Rd
64ebab7d5f327033219e9ade16493fff *man/stan_cmdstan_exists.Rd
b5fbdd1a1c893ac907b542dc9b7735b6 *man/stan_cmdstan_path.Rd
d17ec289db35821bdbf72eae7c692df4 *man/stan_cmdstan_version.Rd
b1243306a1c7269d40b05c257227a557 *man/stan_package_clean.Rd
87f91bf4e5d07e9f231b0027f11f7f25 *man/stan_package_compile.Rd
0273f94d2a8975867359904b12a0b562 *man/stan_package_configure.Rd
b0b3186edbae1cc801617efbe9f7b858 *man/stan_package_create.Rd
5bc45592e40bee8d86fd222c88497128 *man/stan_package_model.Rd
e1dedef1d8b3f0053146d6493facff2b *man/stan_package_model_files.Rd
d79d3ba33b061b3cc115cc0542203701 *src/Makevars
e3e5654735feafbd660a0f71d776d561 *src/cmdstan.c
e7f2f88909d7f80ca3c5bc7ecaf535d0 *man/stan_package_model.Rd
66b0cb46e7696b855970ebd064d7753a *man/stan_package_model_files.Rd
a4ecab67eaecbb32368f00694cca54d7 *src/Makevars
2c33369fea43469f1c5fefe8717024a7 *src/Makevars.win
2fca6d1d2d6f6661d01ff20c1b4a7637 *src/cmdstan.c
628381788283c5283faa3d774b427740 *src/install.libs.R
d8735c47ab789feba7740aa2469b2389 *tests/testthat.R
8c06a6808db95a4bed985c5fa4599739 *tests/testthat/helper-utils.R
14f21ffebd3c0f0bc20d8fd2337fefe3 *tests/testthat/test-stan_cmdstan_exists.R
ae81551b1021675489b285846b01e493 *tests/testthat/test-stan_cmdstan_path.R
a186ffe31969cc03a36f721d8e71bbdf *tests/testthat/test-stan_cmdstan_version.R
7be7c6e16e4e7334ffd21d4a8b04ab6e *tests/testthat/test-stan_on_windows.R
fee0e6e7a8455cbe281f914b7433326e *tests/testthat/test-stan_package_compile.R
1e66d7155ef0cead4f44821619a771b0 *tests/testthat/test-stan_package_configure.R
292d788f467eb24bcb06b9dea52fa506 *tests/testthat/test-stan_package_create.R
e4cd771d0316e35088469f2653673857 *tests/testthat/test-stan_package_compile.R
627682324654b0c559db7be837828ff8 *tests/testthat/test-stan_package_configure.R
86fac9b1248838bb73232aaaef9d6b6f *tests/testthat/test-stan_package_create.R
340ef4d3f71daa1d795a4c0039dae92c *tests/testthat/test-utils_assert.R
4e122d6b839621356a7fba073014c2d7 *tests/testthat/test-utils_logic.R
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export(stan_package_create)
export(stan_package_model)
export(stan_package_model_files)
importFrom(fs,dir_copy)
importFrom(pkglite,unpack)
importFrom(rlang,abort)
importFrom(rlang,check_installed)
importFrom(rlang,inform)
Expand Down
21 changes: 21 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# instantiate 0.2.0

* Remove "internal" installation (#16).
* In the documentation, remove claims that `instantiate` is a good fit for centralized multi-user R environments (c.f. https://github.com/stan-dev/cmdstan/issues/1175).
* Check subdirectories of the fixed CmdStan installation path.

# instantiate 0.1.0

* Use `install.libs.R` for both CmdStan in `instantiate` and Stan model compilation in packages (#1, #9, #12).
* Stan models should now be in `src/stan/` instead of `inst/stan/` (#12). `inst/stan/` should still work for the next few versions, but it is now deprecated. When a modeling package is installed, its `install.libs.R` moves `src/stan/` to `bin/stan/` and then compiles models inside `bin/stan/`.
* Disable staged installation for `instantiate` itself to help the hard-coded paths in CmdStan work as expected in "internal" installation.

# instantiate 0.0.4

* Relax `cmdstanr` requirement (now minimum version 0.5.2).

# instantiate 0.0.3

* Generate a modified tarball of the package which always installs CmdStan internally, regardless of environment variables (#8). The appropriate version of this tarball will be attached to forthcoming releases on GitHub.
* Bug fixes for internal CmdStan installation.

# instantiate 0.0.2

* Address CRAN comments from the submission of version 0.0.1.
Expand Down
14 changes: 10 additions & 4 deletions R/stan_cmdstan_exists.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#' @title Check if `instantiate` can find CmdStan.
#' @title Check if `instantiate` can find CmdStanR and CmdStan.
#' @export
#' @family cmdstan
#' @description Check if `instantiate` can find CmdStan.
#' @description Check if `instantiate` can find CmdStanR and CmdStan.
#' @inheritParams stan_cmdstan_path
#' @return `TRUE` if `instantiate` can find CmdStan, `FALSE` otherwise.
#' @return `TRUE` if `instantiate` can find the CmdStanR R package and the
#' CmdStan command line tool. Returns `FALSE` otherwise.
#' @examples
#' stan_cmdstan_exists()
stan_cmdstan_exists <- function(
cmdstan_install = Sys.getenv("CMDSTAN_INSTALL")
cmdstan_install = Sys.getenv("CMDSTAN_INSTALL", unset = "")
) {
# nocov start
if (!rlang::is_installed("cmdstanr")) {
return(FALSE) # Not possible to cover in regular unit tests.
}
# nocov end
path <- stan_cmdstan_path(cmdstan_install = cmdstan_install)
cmdstan_valid(path)
}
Expand Down
73 changes: 36 additions & 37 deletions R/stan_cmdstan_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,48 @@
#' @return Character of length 1, directory path to CmdStan. The path
#' may or may not exist. Returns the empty string `""` if the path
#' cannot be determined.
#' @param cmdstan_install Character of length 1, how CmdStan was installed. The
#' installation method determines how `instantiate` looks up CmdStan.
#' Set the default value with the `CMDSTAN_INSTALL` environment variable.
#' @param cmdstan_install Character of length 1, how to look for an installed
#' copy of CmdStan. See <https://wlandau.github.io/instantiate/> for details.
#' Choices:
#' 1. `"internal"`: Use the copy of CmdStan installed internally inside the
#' `instantiate` package file system. Before using this option,
#' CmdStan must be installed in the package file system. To do this,
#' set the `CMDSTAN_INSTALL` environment variable to `"internal"` before
#' installing `instantiate`.
#' 2. `"fixed"`: Use the copy of CmdStan that was located at the value
#' contained in `Sys.getenv("CMDSTAN")` at the time `instantiate`
#' was installed. In this case, the path to CmdStan is not inside
#' `instantiate` itself, but it is fixed at installation time
#' and does not depend on the current value of
#' `Sys.getenv("CMDSTAN")` at runtime.
#' 3. `"cmdstanr"`: Let the `cmdstanr::cmdstan_path()` decide where
#' to look for CmdStan. The `cmdstanr` package must be installed. If it
#' is not installed, the function returns the empty string `""`.
#' 4. `""` (default): Try all 3 options in the order above to find a valid
#' installed copy of CmdStan.
#' 1. `""` (default): look at the original value that the `CMDSTAN_INSTALL`
#' environment variable contained when `instantiate` at the time
#' when it was installed.
#' If it was `"implicit"` or `"fixed"`, then choose
#' the corresponding option below. Otherwise, default to `"implicit"`.
#' 2. `"implicit"`: Let the `cmdstanr::cmdstan_path()` decide where
#' to look for CmdStan. As explained in the `cmdstanr` documentation,
#' the output of `cmdstanr::cmdstan_path()` depends
#' on the current value of the `CMDSTAN` environment variable.
#' The `cmdstanr` package must be installed. If it
#' is not installed, then `stan_cmdstan_path()`
#' returns the empty string `""`.
#' 3. `"fixed"`: Use the path to CmdStan that was originally
#' contained in `Sys.getenv("CMDSTAN")` at the time when `instantiate`
#' was installed.
#' @examples
#' stan_cmdstan_path()
stan_cmdstan_path <- function(
cmdstan_install = Sys.getenv("CMDSTAN_INSTALL")
cmdstan_install = Sys.getenv("CMDSTAN_INSTALL", unset = "")
) {
# It is not feasible to test all these cases in a single test coverage run.
# Covered in several GitHub Actions workflows.
# nocov start
install <- stan_cmdstan_install(cmdstan_install)
if (identical(install, "internal") || identical(install, "")) {
parent <- system.file("cmdstan", package = "instantiate", mustWork = FALSE)
out <- file.path(parent, list.files(parent)) %||% ""
}
if (identical(install, "fixed") || path_next(install, out)) {
out <- .Call(c_cmdstan_path)
}
if (identical(install, "cmdstanr") || path_next(install, out)) {
out <- cmdstanr_path()
if (!rlang::is_installed("cmdstanr")) {
return("") # Not possible to cover in regular unit tests.
}
# nocov end
out
}

path_next <- function(install, out) {
identical(install, "") && !any(dir.exists(out))
install <- if_any(
identical(cmdstan_install, ""),
.Call(c_cmdstan_path_install, PACKAGE = "instantiate"),
cmdstan_install
)
stan_assert_install(install)
path <- if_any(
identical(install, "fixed"),
.Call(c_cmdstan_path_fixed, PACKAGE = "instantiate"),
cmdstanr_path()
)
if_any(
cmdstan_valid(path),
path,
cmdstanr("cmdstan_default_path")(dir = path)
) %|||% ""
}
11 changes: 6 additions & 5 deletions R/stan_cmdstan_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
#' package uses. If CmdStan is not found, then the return value depends
#' on the `error_on_NA` argument.
#' @inheritParams stan_cmdstan_path
#' @inheritParams cmdstanr::cmdstan_version
#' @param error_on_NA Logical of length 1, whether an error should be thrown
#' if CmdStan is not found.
#' @examples
#' if (stan_cmdstan_exists()) {
#' message(stan_cmdstan_version())
#' }
stan_cmdstan_version <- function(
cmdstan_install = Sys.getenv("CMDSTAN_INSTALL"),
cmdstan_install = Sys.getenv("CMDSTAN_INSTALL", unset = ""),
error_on_NA = TRUE
) {
stan_assert_cmdstanr()
path_old <- cmdstanr_path()
if (cmdstan_valid(path_old)) {
on.exit(suppressMessages(cmdstanr::set_cmdstan_path(path = path_old)))
on.exit(suppressMessages(cmdstanr("set_cmdstan_path")(path = path_old)))
}
path_new <- stan_cmdstan_path(cmdstan_install = cmdstan_install)
suppressMessages(cmdstanr::set_cmdstan_path(path = path_new))
cmdstanr::cmdstan_version(error_on_NA = error_on_NA)
suppressMessages(cmdstanr("set_cmdstan_path")(path = path_new))
cmdstanr("cmdstan_version")(error_on_NA = error_on_NA)
}
12 changes: 4 additions & 8 deletions R/stan_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@
#' the executables live inside the file systems of their
#' respective packages, and users have the full power
#' and convenience of [`CmdStanR`](https://mc-stan.org/cmdstanr/)
#' without any additional compilation. This approach saves time,
#' allows R package developers to migrate from
#' [`rstan`](https://mc-stan.org/rstan/)
#' to the more modern [`CmdStanR`](https://mc-stan.org/cmdstanr/),
#' and fits well with centrally maintained R installations
#' where users may have trouble installing their own packages,
#' diagnosing compilation errors, and setting environment variables.
#' without any additional compilation after package installation.
#' This approach saves time and helps R package developers
#' migrate from [`rstan`](https://mc-stan.org/rstan/)
#' to the more modern [`CmdStanR`](https://mc-stan.org/cmdstanr/).
#' @useDynLib instantiate, .registration = TRUE
#' @importFrom fs dir_copy
#' @importFrom pkglite unpack
#' @importFrom rlang abort check_installed inform is_installed warn
#' @importFrom utils capture.output globalVariables install.packages
NULL
Expand Down

0 comments on commit 084a6a9

Please sign in to comment.