Skip to content

Commit 682eea7

Browse files
committed
Bootstrap package to generate itself
1 parent 9fcb09c commit 682eea7

File tree

10 files changed

+314
-124
lines changed

10 files changed

+314
-124
lines changed

.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
^\.Rproj\.user$
2626
^_pkgdown\.yml$
2727
^\.gitattributes$
28+
^inst/dust$

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ docs
1515
.valgrind_ignore
1616
inst/doc
1717
pkgdown
18+
inst/dust

R/cpp11.R

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

R/dust.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
## Generated by dust2 (version 0.15.0) - do not edit
12
sir <- function() {
23
dust_system_generator("sir")
34
}
4-
5-
65
walk <- function() {
76
dust_system_generator("walk")
87
}

R/package.R

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@
4949
dust_package <- function(path, quiet = FALSE) {
5050
call <- environment()
5151
## 1. check that the package is legit
52-
desc <- package_validate_root(path, call)
52+
pkg <- package_validate_root(path, call)
5353
path_dust <- file.path(path, "inst/dust")
5454
path_src <- file.path(path, "src")
5555
path_r <- file.path(path, "R")
5656

57-
pkg <- desc$get_field("Package")
5857
if (!quiet) {
5958
cli::cli_alert_info("Working in package '{pkg}' at '{path}'")
6059
}
@@ -112,9 +111,12 @@ package_validate_root <- function(path, call) {
112111
}
113112

114113
desc <- pkgload::pkg_desc(path)
115-
package_validate_has_dep(desc, "dust2", "Imports")
114+
pkg <- desc$get_field("Package")
115+
if (pkg != "dust2") {
116+
package_validate_has_dep(desc, "dust2", "Imports")
117+
package_validate_has_dep(desc, "dust2", "LinkingTo")
118+
}
116119
package_validate_has_dep(desc, "cpp11", "LinkingTo")
117-
package_validate_has_dep(desc, "dust2", "LinkingTo")
118120
package_validate_has_dep(desc, "mcstate2", "LinkingTo")
119121

120122
name <- desc$get_field("Package")
@@ -125,7 +127,7 @@ package_validate_root <- function(path, call) {
125127
}
126128
package_validate_namespace(file.path(path, "NAMESPACE"), name)
127129

128-
desc
130+
pkg
129131
}
130132

131133

inst/template/dust_compare.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ SEXP dust2_discrete_{{name}}_unfilter_run(cpp11::sexp ptr, cpp11::sexp r_pars, c
1313
return dust2::r::dust2_discrete_unfilter_run<{{class}}>(ptr, r_pars, r_initial, save_history, grouped);
1414
}
1515

16+
[[cpp11::register]]
17+
SEXP dust2_discrete_{{name}}_unfilter_last_history(cpp11::sexp ptr, bool grouped) {
18+
return dust2::r::dust2_discrete_unfilter_last_history<{{class}}>(ptr, grouped);
19+
}
20+
1621
[[cpp11::register]]
1722
SEXP dust2_discrete_{{name}}_filter_alloc(cpp11::list r_pars, cpp11::sexp r_time_start, cpp11::sexp r_time, cpp11::sexp r_dt, cpp11::list r_data, cpp11::sexp r_n_particles, cpp11::sexp r_n_groups, cpp11::sexp r_index, cpp11::sexp r_seed) {
1823
return dust2::r::dust2_discrete_filter_alloc<{{class}}>(r_pars, r_time_start, r_time, r_dt, r_data, r_n_particles, r_n_groups, r_index, r_seed);
@@ -23,6 +28,11 @@ SEXP dust2_discrete_{{name}}_filter_run(cpp11::sexp ptr, cpp11::sexp r_pars, cpp
2328
return dust2::r::dust2_discrete_filter_run<{{class}}>(ptr, r_pars, r_initial, save_history, grouped);
2429
}
2530

31+
[[cpp11::register]]
32+
SEXP dust2_discrete_{{name}}_filter_last_history(cpp11::sexp ptr, bool grouped) {
33+
return dust2::r::dust2_discrete_filter_last_history<{{class}}>(ptr, grouped);
34+
}
35+
2636
[[cpp11::register]]
2737
SEXP dust2_discrete_{{name}}_filter_rng_state(cpp11::sexp ptr) {
2838
return dust2::r::dust2_discrete_filter_rng_state<{{class}}>(ptr);

scripts/update_example

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ examples <- c("sir.cpp", "walk.cpp")
44
setwd(here::here())
55
unlink(file.path("src", basename(examples)))
66

7+
unlink("inst/dust", recursive = TRUE)
8+
dir.create("inst/dust", FALSE)
9+
stopifnot(all(
10+
file.copy(file.path("inst/examples", examples), "inst/dust",
11+
overwrite = TRUE)))
712
pkgload::load_all()
8-
path <- withr::with_dir("tests/testthat",
9-
create_test_package(examples = examples))
10-
path <- dust_package(path, quiet = TRUE)
11-
file.copy(file.path(path, "R", "dust.R"), "R", overwrite = TRUE)
12-
unlink(file.path(path, "src", "cpp11.cpp"))
13-
unlink(file.path(path, "src", "Makevars"))
14-
file.copy(dir(file.path(path, "src"), full.names = TRUE), "src",
15-
overwrite = TRUE)
16-
cpp11::cpp_register()
13+
dust_package(".")
14+
code <- readLines("R/dust.R")
15+
writeLines(sub("dust2::+", "", code), "R/dust.R")
16+
17+
unlink("inst/dust", recursive = TRUE)

src/cpp11.cpp

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)