2121# ' @aliases rstan_package_skeleton
2222# '
2323# ' @description
24- # ' \if{html}{\figure{stanlogo .png}{options: width="25" alt="https://mc-stan.org/about/logo/"}}
24+ # ' \if{html}{\figure{logo.svg .png}{options: width="25" alt="https://mc-stan.org/about/logo/"}}
2525# ' The `rstan_create_package()` function helps get you started developing a
2626# ' new \R package that interfaces with Stan via the \pkg{rstan} package. First
2727# ' the basic package structure is set up via [usethis::create_package()].
118118# ' @template seealso-vignettes
119119# ' @template seealso-get-help
120120# '
121- rstan_create_package <- function (path ,
122- fields = NULL ,
123- rstudio = TRUE ,
124- open = TRUE ,
125- stan_files = character (),
126- roxygen = TRUE ,
127- travis = FALSE ,
128- license = TRUE ,
129- auto_config = TRUE ) {
121+ rstan_create_package <- function (
122+ path ,
123+ fields = NULL ,
124+ rstudio = TRUE ,
125+ open = TRUE ,
126+ stan_files = character (),
127+ roxygen = TRUE ,
128+ travis = FALSE ,
129+ license = TRUE ,
130+ auto_config = TRUE
131+ ) {
130132 if (! requireNamespace(" usethis" , quietly = TRUE )) {
131- stop(" Please install package 'usethis' to use function 'rstan_create_package'." ,
132- call. = FALSE )
133+ stop(
134+ " Please install package 'usethis' to use function 'rstan_create_package'." ,
135+ call. = FALSE
136+ )
133137 }
134138 DIR <- dirname(path )
135139 name <- basename(path )
136140 .check_stan_ext(stan_files )
137141
138142 if (rstudio && ! requireNamespace(" rstudioapi" , quietly = TRUE )) {
139- stop(" Please install package 'rstudioapi' to use option 'rstudio = TRUE'." ,
140- call. = FALSE )
143+ stop(
144+ " Please install package 'rstudioapi' to use option 'rstudio = TRUE'." ,
145+ call. = FALSE
146+ )
141147 rstudio <- rstudio && rstudioapi :: isAvailable()
142148 }
143149 if (open && rstudio ) {
@@ -169,28 +175,48 @@ rstan_create_package <- function(path,
169175# check stan extensions
170176.check_stan_ext <- function (stan_files ) {
171177 if (length(stan_files ) && ! all(grepl(" \\ .stan$" , stan_files ))) {
172- stop(" All files named in 'stan_files' must end " ,
173- " with a '.stan' extension." , call. = FALSE )
178+ stop(
179+ " All files named in 'stan_files' must end " ,
180+ " with a '.stan' extension." ,
181+ call. = FALSE
182+ )
174183 }
175184}
176185
177186# add travis file
178187.add_travis <- function (pkgdir ) {
179188 travis_file <- readLines(.system_file(" travis.yml" ))
180- .add_stanfile(gsub(" RSTAN_PACKAGE_NAME" , basename(pkgdir ), travis_file ),
181- pkgdir , " .travis.yml" ,
182- noedit = FALSE , msg = TRUE , warn = FALSE )
189+ .add_stanfile(
190+ gsub(" RSTAN_PACKAGE_NAME" , basename(pkgdir ), travis_file ),
191+ pkgdir ,
192+ " .travis.yml" ,
193+ noedit = FALSE ,
194+ msg = TRUE ,
195+ warn = FALSE
196+ )
183197}
184198
185199# add .gitignore and .Rbuildignore files
186200.add_gitignore_Rbuildignore <- function (pkgdir , travis ) {
187201 gitignore_files <- c(" ^rcppExports.cpp$" , " ^stanExports_*" )
188- .add_stanfile(gitignore_files , pkgdir , " .gitignore" ,
189- noedit = FALSE , msg = TRUE , warn = FALSE )
202+ .add_stanfile(
203+ gitignore_files ,
204+ pkgdir ,
205+ " .gitignore" ,
206+ noedit = FALSE ,
207+ msg = TRUE ,
208+ warn = FALSE
209+ )
190210
191211 Rbuildignore_files <- c(gitignore_files , if (travis ) " ^\\ .travis\\ .yml$" )
192- .add_stanfile(Rbuildignore_files , pkgdir , " .Rbuildignore" ,
193- noedit = FALSE , msg = TRUE , warn = FALSE )
212+ .add_stanfile(
213+ Rbuildignore_files ,
214+ pkgdir ,
215+ " .Rbuildignore" ,
216+ noedit = FALSE ,
217+ msg = TRUE ,
218+ warn = FALSE
219+ )
194220}
195221
196222# add R/mypkg-package.R file with roxygen import comments
@@ -199,9 +225,15 @@ rstan_create_package <- function(path,
199225 pkg_file <- readLines(.system_file(" rstanpkg-package.R" ))
200226 pkg_file <- gsub(" RSTAN_PACKAGE_NAME" , basename(pkgdir ), pkg_file )
201227 pkg_file <- gsub(" RSTAN_REFERENCE" , .rstan_reference(), pkg_file )
202- .add_stanfile(pkg_file , pkgdir ,
203- " R" , paste0(basename(pkgdir ), " -package.R" ),
204- noedit = FALSE , msg = TRUE , warn = FALSE )
228+ .add_stanfile(
229+ pkg_file ,
230+ pkgdir ,
231+ " R" ,
232+ paste0(basename(pkgdir ), " -package.R" ),
233+ noedit = FALSE ,
234+ msg = TRUE ,
235+ warn = FALSE
236+ )
205237 desc_pkg <- desc :: description $ new(file.path(pkgdir , " DESCRIPTION" ))
206238 desc_pkg $ set(Encoding = " UTF-8" )
207239 desc_pkg $ write()
@@ -210,25 +242,40 @@ rstan_create_package <- function(path,
210242# reference to rstan package
211243.rstan_reference <- function () {
212244 has_version <- utils :: packageDescription(" rstan" , fields = " Version" )
213- version_year <- substr(utils :: packageDescription(" rstan" , fields = " Date" ), 1 , 4 )
245+ version_year <- substr(
246+ utils :: packageDescription(" rstan" , fields = " Date" ),
247+ 1 ,
248+ 4
249+ )
214250 paste0(
215- " Stan Development Team (" , version_year ," ). " ,
251+ " Stan Development Team (" ,
252+ version_year ,
253+ " ). " ,
216254 " RStan: the R interface to Stan. " ,
217- " R package version " , has_version , " . " ,
255+ " R package version " ,
256+ has_version ,
257+ " . " ,
218258 " https://mc-stan.org"
219259 )
220260}
221261
222262# add stan functionality to package
223- .rstan_make_pkg <- function (pkgdir , stan_files ,
224- roxygen , travis , license , auto_config ) {
225-
263+ .rstan_make_pkg <- function (
264+ pkgdir ,
265+ stan_files ,
266+ roxygen ,
267+ travis ,
268+ license ,
269+ auto_config
270+ ) {
226271 use_rstan(pkgdir , license = license , auto_config = auto_config )
227272 file.copy(
228273 from = stan_files ,
229274 to = file.path(pkgdir , " inst" , " stan" , basename(stan_files ))
230275 )
231- if (roxygen ) .add_roxygen(pkgdir )
276+ if (roxygen ) {
277+ .add_roxygen(pkgdir )
278+ }
232279 if (travis ) {
233280 .add_travis(pkgdir )
234281 warning(
@@ -301,7 +348,6 @@ rstan_create_package <- function(path,
301348# # error:
302349# # - when {dir/file}.create fails even though it doesn't exist
303350
304-
305351# # ok stan_meta_header.hpp is problematic, because want to warn if already exists, but only if it's there from before...
306352
307353# # so .add_stanfile(file_lines, pkgdir, ...,
0 commit comments