diff --git a/DESCRIPTION b/DESCRIPTION index b282d978..295459a6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -84,9 +84,9 @@ Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 -SystemRequirements: Python (>= 2.7.0) with header files and shared - library; TensorFlow (v1.14; https://www.tensorflow.org/); TensorFlow - Probability (v0.7.0; https://www.tensorflow.org/probability/) +SystemRequirements: Python (>= 3.7.0) with header files and shared + library; TensorFlow (>= v2.0.0; https://www.tensorflow.org/); TensorFlow + Probability (v0.8.0; https://www.tensorflow.org/probability/) Collate: 'package.R' 'utils.R' diff --git a/codemeta.json b/codemeta.json index 52a52b64..798479d7 100644 --- a/codemeta.json +++ b/codemeta.json @@ -4,16 +4,17 @@ "identifier": "greta", "description": "Write statistical models in R and fit them by MCMC and optimisation on CPUs and GPUs, using Google 'TensorFlow'. greta lets you write your own model like in BUGS, JAGS and Stan, except that you write models right in R, it scales well to massive datasets, and it’s easy to extend and build on. See the website for more information, including tutorials, examples, package documentation, and the greta forum.", "name": "greta: Simple and Scalable Statistical Modelling in R", - "codeRepository": "https://github.com/njtierney/greta", + "relatedLink": ["https://greta-stats.org", "https://CRAN.R-project.org/package=greta"], + "codeRepository": "https://github.com/greta-dev/greta", "issueTracker": "https://github.com/greta-dev/greta/issues", "license": "https://spdx.org/licenses/Apache-2.0", - "version": "0.4.4", + "version": "0.5.0", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", "url": "https://r-project.org" }, - "runtimePlatform": "R version 4.3.2 (2023-10-31)", + "runtimePlatform": "R version 4.4.2 (2024-10-31)", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -156,6 +157,18 @@ }, "sameAs": "https://CRAN.R-project.org/package=DiagrammeR" }, + { + "@type": "SoftwareApplication", + "identifier": "dplyr", + "name": "dplyr", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=dplyr" + }, { "@type": "SoftwareApplication", "identifier": "DiagrammeRsvg", @@ -276,6 +289,18 @@ }, "sameAs": "https://CRAN.R-project.org/package=mvtnorm" }, + { + "@type": "SoftwareApplication", + "identifier": "purrr", + "name": "purrr", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=purrr" + }, { "@type": "SoftwareApplication", "identifier": "rmarkdown", @@ -339,15 +364,27 @@ }, { "@type": "SoftwareApplication", - "identifier": "tidyverse", - "name": "tidyverse", + "identifier": "tibble", + "name": "tibble", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=tibble" + }, + { + "@type": "SoftwareApplication", + "identifier": "tidyr", + "name": "tidyr", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", "name": "Comprehensive R Archive Network (CRAN)", "url": "https://cran.r-project.org" }, - "sameAs": "https://CRAN.R-project.org/package=tidyverse" + "sameAs": "https://CRAN.R-project.org/package=tidyr" }, { "@type": "SoftwareApplication", @@ -372,6 +409,18 @@ "url": "https://cran.r-project.org" }, "sameAs": "https://CRAN.R-project.org/package=withr" + }, + { + "@type": "SoftwareApplication", + "identifier": "rstudioapi", + "name": "rstudioapi", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=rstudioapi" } ], "softwareRequirements": { @@ -379,7 +428,7 @@ "@type": "SoftwareApplication", "identifier": "R", "name": "R", - "version": ">= 3.1.0" + "version": ">= 4.1.0" }, "2": { "@type": "SoftwareApplication", @@ -409,7 +458,7 @@ "@type": "SoftwareApplication", "identifier": "cli", "name": "cli", - "version": ">= 3.0.0", + "version": ">= 3.4.1", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -513,10 +562,22 @@ "sameAs": "https://CRAN.R-project.org/package=reticulate" }, "13": { + "@type": "SoftwareApplication", + "identifier": "rlang", + "name": "rlang", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=rlang" + }, + "14": { "@type": "SoftwareApplication", "identifier": "tensorflow", "name": "tensorflow", - "version": ">= 2.7.0", + "version": "== 2.16.0", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -525,7 +586,29 @@ }, "sameAs": "https://CRAN.R-project.org/package=tensorflow" }, - "14": { + "15": { + "@type": "SoftwareApplication", + "identifier": "tools", + "name": "tools" + }, + "16": { + "@type": "SoftwareApplication", + "identifier": "utils", + "name": "utils" + }, + "17": { + "@type": "SoftwareApplication", + "identifier": "whisker", + "name": "whisker", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=whisker" + }, + "18": { "@type": "SoftwareApplication", "identifier": "yesno", "name": "yesno", @@ -537,9 +620,9 @@ }, "sameAs": "https://CRAN.R-project.org/package=yesno" }, - "SystemRequirements": "Python (>= 2.7.0) with header files and shared\n library; TensorFlow (v1.14; https://www.tensorflow.org/); TensorFlow\n Probability (v0.7.0; https://www.tensorflow.org/probability/)" + "SystemRequirements": "Python (>= 3.7.0) with header files and shared\n library; TensorFlow (>= v2.0.0; https://www.tensorflow.org/); TensorFlow\n Probability (v0.8.0; https://www.tensorflow.org/probability/)" }, - "fileSize": "2098.014KB", + "fileSize": "1625.784KB", "citation": [ { "@type": "ScholarlyArticle", @@ -569,8 +652,7 @@ } } ], - "relatedLink": "https://greta-stats.org", - "releaseNotes": "https://github.com/njtierney/greta/blob/master/NEWS.md", - "readme": "https://github.com/njtierney/greta/blob/master/README.md", - "contIntegration": ["https://app.codecov.io/gh/greta-dev/greta?branch=master", "https://github.com/greta-dev/greta/actions"] + "releaseNotes": "https://github.com/greta-dev/greta/blob/master/NEWS.md", + "readme": "https://github.com/greta-dev/greta/blob/master/README.md", + "contIntegration": ["https://github.com/greta-dev/greta/actions", "https://app.codecov.io/gh/greta-dev/greta?branch=master"] } diff --git a/cran-comments.md b/cran-comments.md index 4066c41c..452a0cfa 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,20 +1,28 @@ ## Test environments -* local R installation, R 4.3.3 +* local R installation, R 4.4.2 * win-builder (devel) ## R CMD check results -0 errors | 0 warnings | 0 notes +0 errors | 0 warnings | 1 notes -* Days since last update: 38 +> Found the following (possibly) invalid URLs: + URL: http://www.phidot.org/software/mark/docs/book/ + From: inst/doc/example_models.html + Status: 403 + Message: Forbidden + +We could not find an issue with this link, or an alternative link. + +* Days since last update: 244 days ## Submission notes -This release is due to a bug we discovered with trailing commas from the `glue` package (https://github.com/tidyverse/glue/issues/320). It is a very small change, but it is very critical. We have also +This release is a substantial overhaul of the internals of greta to migrate the internals from tensorflow 1 to tensorflow 2. ## revdepcheck results -We checked 3 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. +We checked 1 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. * We saw 0 new problems * We failed to check 0 packages diff --git a/inst/CITATION b/inst/CITATION index f857195c..e80c2123 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -1,19 +1,11 @@ -citHeader("To cite greta in publications use:") - -citEntry(entry = "Article", - title = "{greta}: simple and scalable statistical modelling in R", - author = personList(as.person("Nick Golding")), - journal = "Journal of Open Source Software", - year = "2019", - volume = "4", - number = "40", - pages = "1601", - url = "http://dx.doi.org/10.21105/joss.01601", - doi = "10.21105/joss.01601", - - textVersion = - paste("Nick Golding (2019).", - "greta: simple and scalable statistical modelling in R.", - "Journal of Open Source Software, 4(40), 1601.", - "URL http://dx.doi.org/10.21105/joss.01601.") +bibentry( + bibtype = "Article", + title = "{greta}: simple and scalable statistical modelling in R", + author = "Nick Golding", + journal = "Journal of Open Source Software", + year = 2019, + volume = 4, + number = 40, + pages = 1601, + doi = "10.21105/joss.01601" ) diff --git a/revdep/checks.noindex/libraries.csv b/revdep/checks.noindex/libraries.csv index 0b02e6a8..b0fcc7d9 100644 --- a/revdep/checks.noindex/libraries.csv +++ b/revdep/checks.noindex/libraries.csv @@ -1,4 +1,44 @@ package,old,new,delta -greta,0.4.3,0.4.4,* -future,NA,1.33.1,* -Rcpp,NA,1.0.12,* +greta,0.4.5,0.5.0,* +abind,1.4-8,1.4-8, +backports,1.5.0,1.5.0, +base64enc,0.1-3,0.1-3, +callr,3.7.6,3.7.6, +cli,3.6.3,3.6.3, +coda,0.19-4.1,0.19-4.1, +config,0.3.2,0.3.2, +crayon,1.5.3,1.5.3, +digest,0.6.37,0.6.37, +future,1.34.0,1.34.0, +globals,0.16.3,0.16.3, +glue,1.8.0,1.8.0, +here,1.0.1,1.0.1, +hms,1.1.3,1.1.3, +jsonlite,1.8.9,1.8.9, +lifecycle,1.0.4,1.0.4, +listenv,0.9.1,0.9.1, +magrittr,2.0.3,2.0.3, +parallelly,1.38.0,1.38.0, +pkgconfig,2.0.3,2.0.3, +png,0.1-8,0.1-8, +prettyunits,1.2.0,1.2.0, +processx,3.8.4,3.8.4, +progress,1.2.3,1.2.3, +ps,1.8.1,1.8.1, +R6,2.5.1,2.5.1, +rappdirs,0.3.3,0.3.3, +Rcpp,1.0.13-1,1.0.13-1, +RcppTOML,0.2.2,0.2.2, +reticulate,1.39.0,1.39.0, +rlang,1.1.4,1.1.4, +rprojroot,2.0.4,2.0.4, +rstudioapi,0.17.1,0.17.1, +tensorflow,2.16.0,2.16.0, +tfautograph,0.3.2,0.3.2, +tfruns,1.5.3,1.5.3, +tidyselect,1.2.1,1.2.1, +vctrs,0.6.5,0.6.5, +whisker,0.4.1,0.4.1, +withr,3.0.2,3.0.2, +yaml,2.3.10,2.3.10, +yesno,0.1.3,0.1.3, diff --git a/revdep/checks.noindex/runMCMCbtadjust/new/libraries.txt b/revdep/checks.noindex/runMCMCbtadjust/new/libraries.txt index e21edfb6..862d1852 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/new/libraries.txt +++ b/revdep/checks.noindex/runMCMCbtadjust/new/libraries.txt @@ -1,125 +1,180 @@ Library: /Users/nick/github/greta-dev/greta/revdep/library.noindex/greta/new -future (1.33.1) -greta (0.4.4) -Rcpp (1.0.12) +abind (1.4-8) +backports (1.5.0) +base64enc (0.1-3) +callr (3.7.6) +cli (3.6.3) +coda (0.19-4.1) +config (0.3.2) +crayon (1.5.3) +digest (0.6.37) +future (1.34.0) +globals (0.16.3) +glue (1.8.0) +greta (0.5.0) +here (1.0.1) +hms (1.1.3) +jsonlite (1.8.9) +lifecycle (1.0.4) +listenv (0.9.1) +magrittr (2.0.3) +parallelly (1.38.0) +pkgconfig (2.0.3) +png (0.1-8) +prettyunits (1.2.0) +processx (3.8.4) +progress (1.2.3) +ps (1.8.1) +R6 (2.5.1) +rappdirs (0.3.3) +Rcpp (1.0.13-1) +RcppTOML (0.2.2) +reticulate (1.39.0) +rlang (1.1.4) +rprojroot (2.0.4) +rstudioapi (0.17.1) +tensorflow (2.16.0) +tfautograph (0.3.2) +tfruns (1.5.3) +tidyselect (1.2.1) +vctrs (0.6.5) +whisker (0.4.1) +withr (3.0.2) +yaml (2.3.10) +yesno (0.1.3) Library: /Users/nick/github/greta-dev/greta/revdep/library.noindex/runMCMCbtadjust -abind (1.4-5) -backports (1.4.1) -base64enc (0.1-3) -BH (1.84.0-0) -bit (4.0.5) -bit64 (4.0.5) -brio (1.1.4) -broom (1.0.5) -broom.helpers (1.14.0) -callr (3.7.3) -checkmate (2.3.1) -cli (3.6.2) -clipr (0.8.0) -coda (0.19-4) -codetools (0.2-19) -colorspace (2.1-0) -commonmark (1.9.0) -config (0.3.2) -cpp11 (0.4.7) -crayon (1.5.2) -desc (1.4.3) -diffobj (0.3.5) -digest (0.6.34) -dplyr (1.1.4) -ellipsis (0.3.2) -evaluate (0.23) -fansi (1.0.6) -farver (2.1.1) -forcats (1.0.0) -fs (1.6.3) -future (1.33.1) -generics (0.1.3) -GGally (2.2.0) -ggmcmc (1.5.1.1) -ggplot2 (3.4.4) -ggstats (0.5.1) -globals (0.16.2) -glue (1.7.0) -gridExtra (2.3) -gtable (0.3.4) -haven (2.5.4) -here (1.0.1) -highr (0.10) -hms (1.1.3) -igraph (1.6.0) -inline (0.3.19) -isoband (0.2.7) -jsonlite (1.8.8) -knitr (1.45) -labeling (0.4.3) -labelled (2.12.0) -lattice (0.22-5) -lifecycle (1.0.4) -listenv (0.9.0) -loo (2.6.0) -magrittr (2.0.3) -markdown (1.12) -MASS (7.3-60.0.1) -Matrix (1.6-5) -matrixStats (1.2.0) -mgcv (1.9-1) -munsell (0.5.0) -nimble (1.0.1) -nlme (3.1-164) -numDeriv (2016.8-1.1) -parallelly (1.36.0) -patchwork (1.2.0) -pillar (1.9.0) -pkgbuild (1.4.3) -pkgconfig (2.0.3) -pkgload (1.3.3) -plyr (1.8.9) -png (0.1-8) -pracma (2.4.4) -praise (1.0.0) -prettyunits (1.2.0) -processx (3.8.3) -progress (1.2.3) -ps (1.7.5) -purrr (1.0.2) -QuickJSR (1.0.9) -R6 (2.5.1) -rappdirs (0.3.3) -RColorBrewer (1.1-3) -Rcpp (1.0.12) -RcppEigen (0.3.3.9.4) -RcppParallel (5.1.7) -RcppTOML (0.2.2) -readr (2.1.5) -rematch2 (2.1.2) -reticulate (1.34.0) -rjags (4-15) -rlang (1.1.3) -rprojroot (2.0.4) -rstan (2.32.5) -rstudioapi (0.15.0) -runjags (2.2.2-1.1) -scales (1.3.0) -StanHeaders (2.32.5) -stringi (1.8.3) -stringr (1.5.1) -tensorflow (2.14.0) -testthat (3.2.1) -tfautograph (0.3.2) -tfruns (1.5.1) -tibble (3.2.1) -tidyr (1.3.0) -tidyselect (1.2.0) -tzdb (0.4.0) -utf8 (1.2.4) -vctrs (0.6.5) -viridisLite (0.4.2) -vroom (1.6.5) -waldo (0.5.2) -whisker (0.4.1) -withr (2.5.2) -xfun (0.41) -yaml (2.3.8) -yesno (0.1.2) +abind (1.4-8) +backports (1.5.0) +base64enc (0.1-3) +BH (1.84.0-0) +brio (1.1.5) +bslib (0.8.0) +cachem (1.1.0) +callr (3.7.6) +checkmate (2.3.2) +cli (3.6.3) +cluster (2.1.6) +coda (0.19-4.1) +codetools (0.2-20) +colorspace (2.1-1) +commonmark (1.9.2) +config (0.3.2) +cpp11 (0.5.0) +crayon (1.5.3) +data.table (1.16.2) +desc (1.4.3) +diffobj (0.3.5) +digest (0.6.37) +distributional (0.5.0) +dplyr (1.1.4) +evaluate (1.0.1) +fansi (1.0.6) +farver (2.1.2) +fastmap (1.2.0) +fontawesome (0.5.2) +forcats (1.0.0) +foreign (0.8-87) +Formula (1.2-5) +fs (1.6.5) +future (1.34.0) +generics (0.1.3) +GGally (2.2.1) +ggmcmc (1.5.1.1) +ggplot2 (3.5.1) +ggstats (0.7.0) +globals (0.16.3) +glue (1.8.0) +gridExtra (2.3) +gtable (0.3.6) +here (1.0.1) +highr (0.11) +Hmisc (5.2-0) +hms (1.1.3) +htmlTable (2.4.3) +htmltools (0.5.8.1) +htmlwidgets (1.6.4) +igraph (2.1.1) +inline (0.3.19) +isoband (0.2.7) +jquerylib (0.1.4) +jsonlite (1.8.9) +knitr (1.48) +labeling (0.4.3) +lattice (0.22-6) +lifecycle (1.0.4) +listenv (0.9.1) +loo (2.8.0) +magrittr (2.0.3) +markdown (1.13) +MASS (7.3-61) +Matrix (1.7-1) +matrixStats (1.4.1) +memoise (2.0.1) +mgcv (1.9-1) +mime (0.12) +moments (0.14.1) +munsell (0.5.1) +nimble (1.2.1) +nimbleAPT (1.0.6) +nimbleHMC (0.2.2) +nlme (3.1-166) +nnet (7.3-19) +numDeriv (2016.8-1.1) +parallelly (1.38.0) +patchwork (1.3.0) +pillar (1.9.0) +pkgbuild (1.4.5) +pkgconfig (2.0.3) +pkgload (1.4.0) +plyr (1.8.9) +png (0.1-8) +posterior (1.6.0) +pracma (2.4.4) +praise (1.0.0) +prettyunits (1.2.0) +processx (3.8.4) +progress (1.2.3) +ps (1.8.1) +purrr (1.0.2) +QuickJSR (1.4.0) +R6 (2.5.1) +rappdirs (0.3.3) +RColorBrewer (1.1-3) +Rcpp (1.0.13-1) +RcppEigen (0.3.4.0.2) +RcppParallel (5.1.9) +RcppTOML (0.2.2) +reticulate (1.39.0) +rjags (4-16) +rlang (1.1.4) +rmarkdown (2.29) +rpart (4.1.23) +rprojroot (2.0.4) +rstan (2.32.6) +rstudioapi (0.17.1) +runjags (2.2.2-4) +sass (0.4.9) +scales (1.3.0) +StanHeaders (2.32.10) +stringi (1.8.4) +stringr (1.5.1) +tensorA (0.36.2.1) +tensorflow (2.16.0) +testthat (3.2.1.1) +tfautograph (0.3.2) +tfruns (1.5.3) +tibble (3.2.1) +tidyr (1.3.1) +tidyselect (1.2.1) +tinytex (0.54) +utf8 (1.2.4) +vctrs (0.6.5) +viridis (0.6.5) +viridisLite (0.4.2) +waldo (0.6.0) +whisker (0.4.1) +withr (3.0.2) +xfun (0.49) +yaml (2.3.10) +yesno (0.1.3) diff --git a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/00check.log b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/00check.log index bde7cad7..45a34797 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/00check.log +++ b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/00check.log @@ -1,15 +1,15 @@ * using log directory ‘/Users/nick/github/greta-dev/greta/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck’ -* using R version 4.3.2 (2023-10-31) -* using platform: aarch64-apple-darwin20 (64-bit) +* using R version 4.4.2 (2024-10-31) +* using platform: aarch64-apple-darwin20 * R was compiled by Apple clang version 14.0.0 (clang-1400.0.29.202) GNU Fortran (GCC) 12.2.0 -* running under: macOS Sonoma 14.0 +* running under: macOS Sonoma 14.5 * using session charset: UTF-8 * using options ‘--no-manual --no-build-vignettes’ * checking for file ‘runMCMCbtadjust/DESCRIPTION’ ... OK * checking extension type ... Package -* this is package ‘runMCMCbtadjust’ version ‘1.0.5’ +* this is package ‘runMCMCbtadjust’ version ‘1.1.2’ * package encoding: UTF-8 * checking package namespace information ... OK * checking package dependencies ... OK @@ -23,15 +23,12 @@ * checking installed package size ... OK * checking package directory ... OK * checking ‘build’ directory ... OK -* checking DESCRIPTION meta-information ... WARNING -Non-standard license specification: - CECILL-2.1 -Standardizable: FALSE +* checking DESCRIPTION meta-information ... OK * checking top-level files ... OK * checking for left-over files ... OK * checking index information ... OK * checking package subdirectories ... OK -* checking R files for non-ASCII characters ... OK +* checking code files for non-ASCII characters ... OK * checking R files for syntax errors ... OK * checking whether the package can be loaded ... OK * checking whether the package can be loaded with stated dependencies ... OK @@ -39,7 +36,11 @@ Standardizable: FALSE * checking whether the namespace can be loaded with stated dependencies ... OK * checking whether the namespace can be unloaded cleanly ... OK * checking loading without being on the library search path ... OK -* checking dependencies in R code ... OK +* checking dependencies in R code ... NOTE +'library' or 'require' calls in package code: + ‘nimble’ ‘nimbleAPT’ + Please use :: or requireNamespace() instead. + See section 'Suggested packages' in the 'Writing R Extensions' manual. * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK @@ -59,9 +60,11 @@ Standardizable: FALSE * checking tests ... OK Running ‘testthat.R’ * checking for unstated dependencies in vignettes ... OK -* checking package vignettes in ‘inst/doc’ ... OK +* checking package vignettes ... OK * checking running R code from vignettes ... NONE - ‘runMCMCbtadjust_Presentation.Rmd’ using ‘UTF-8’... OK + ‘runMCMCbtadjust_Nimble_variations.Rmd’ using ‘UTF-8’... OK + ‘runMCMCbtadjust_Pres.Rmd’ using ‘UTF-8’... OK + ‘runMCMCbtadjust_extraCalculations.Rmd’ using ‘UTF-8’... OK * checking re-building of vignette outputs ... SKIPPED * DONE -Status: 1 WARNING +Status: 1 NOTE diff --git a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/00install.out b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/00install.out index 173f6d8a..16cb286f 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/00install.out +++ b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/00install.out @@ -6,6 +6,7 @@ ** byte-compile and prepare package for lazy loading ** help *** installing help indices +*** copying figures ** building package indices ** installing vignettes ** testing if installed package can be loaded from temporary location diff --git a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.R b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.R index ece014bd..05b5a58c 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.R +++ b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.R @@ -6,72 +6,121 @@ library('runMCMCbtadjust') base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') cleanEx() -nameEx("runMCMC_btadjust") -### * runMCMC_btadjust +nameEx("findMCMC_strong_corrs") +### * findMCMC_strong_corrs flush(stderr()); flush(stdout()) -### Name: runMCMC_btadjust -### Title: runMCMC_btadjust -### Aliases: runMCMC_btadjust +### Name: findMCMC_strong_corrs +### Title: findMCMC_strong_corrs +### Aliases: findMCMC_strong_corrs ### ** Examples - #\code{ -# for examples with Nimble or Greta, see the Vignette. -# condition variable of whether installation is OK with Jags to avoid error durong package check -condition_jags<-TRUE -if (nchar(system.file(package='rjags'))==0) {condition_jags<-FALSE} -if (nchar(system.file(package='runjags'))==0) {condition_jags<-FALSE} -if (condition_jags) -{suppressWarnings(temp<-runjags::testjags(silent=TRUE)) - if(!(temp$JAGS.available&temp$JAGS.found&temp$JAGS.major==4)) {condition_jags<-FALSE}} - -if (condition_jags) { -#generating data -set.seed(1) -y1000<-rnorm(n=1000,mean=600,sd=30) -ModelData <-list(mass = y1000,nobs = length(y1000)) +## Not run: +##D #generating data +##D set.seed(1) +##D y1000<-rnorm(n=1000,mean=600,sd=30) +##D ModelData <-list(mass = y1000,nobs = length(y1000)) +##D +##D #writing the Jags code as a character chain in R +##D modeltotransfer<-"model { +##D +##D # Priors +##D population.mean ~ dunif(0,5000) +##D population.sd ~ dunif(0,100) +##D +##D # Precision = 1/variance: Normal distribution parameterized by precision in Jags +##D population.variance <- population.sd * population.sd +##D precision <- 1 / population.variance +##D +##D # Likelihood +##D for(i in 1:nobs){ +##D mass[i] ~ dnorm(population.mean, precision) +##D } +##D }" +##D +##D #specifying the initial values +##D ModelInits <- function() +##D {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} +##D params <- c("population.mean", "population.sd", "population.variance") +##D K<-3 +##D set.seed(1) +##D Inits<-lapply(1:K,function(x){ModelInits()}) +##D +##D # running runMCMC_btadjust with MCMC_language="Jags": +##D set.seed(1) +##D out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, +##D data=ModelData, +##D Nchains=K, params=params, inits=Inits, +##D niter.min=1000, niter.max=300000, +##D nburnin.min=100, nburnin.max=200000, +##D thin.min=1, thin.max=1000, +##D neff.min=1000, conv.max=1.05, +##D control=list(print.diagnostics=TRUE, neff.method="Coda")) +##D +##D findMCMC_strong_corrs(out.mcmc.Coda) +## End(Not run) -#writing the Jags code as a character chain in R -modeltotransfer<-"model { -# Priors -population.mean ~ dunif(0,5000) -population.sd ~ dunif(0,100) -# Precision = 1/variance: Normal distribution parameterized by precision in Jags -population.variance <- population.sd * population.sd -precision <- 1 / population.variance +cleanEx() +nameEx("runMCMC_btadjust") +### * runMCMC_btadjust -# Likelihood -for(i in 1:nobs){ - mass[i] ~ dnorm(population.mean, precision) - } - }" +flush(stderr()); flush(stdout()) -#specifying the initial values -ModelInits <- function() -{list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} -params <- c("population.mean", "population.sd", "population.variance") -K<-3 -set.seed(1) -Inits<-lapply(1:K,function(x){ModelInits()}) +### Name: runMCMC_btadjust +### Title: runMCMC_btadjust +### Aliases: runMCMC_btadjust -# running runMCMC_btadjust with MCMC_language="Jags": -set.seed(1) -out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, -data=ModelData, -Nchains=K, params=params, inits=Inits, -niter.min=1000, niter.max=300000, -nburnin.min=100, nburnin.max=200000, -thin.min=1, thin.max=1000, -neff.min=1000, conv.max=1.05, -control=list(print.diagnostics=TRUE, neff.method="Coda")) +### ** Examples -summary(out.mcmc.Coda) -} -#} +# for examples with Nimble or Greta, see the Presentation Vignette. +## Not run: +##D #generating data +##D set.seed(1) +##D y1000<-rnorm(n=1000,mean=600,sd=30) +##D ModelData <-list(mass = y1000,nobs = length(y1000)) +##D +##D #writing the Jags code as a character chain in R +##D modeltotransfer<-"model { +##D +##D # Priors +##D population.mean ~ dunif(0,5000) +##D population.sd ~ dunif(0,100) +##D +##D # Precision = 1/variance: Normal distribution parameterized by precision in Jags +##D population.variance <- population.sd * population.sd +##D precision <- 1 / population.variance +##D +##D # Likelihood +##D for(i in 1:nobs){ +##D mass[i] ~ dnorm(population.mean, precision) +##D } +##D }" +##D +##D #specifying the initial values +##D ModelInits <- function() +##D {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} +##D params <- c("population.mean", "population.sd", "population.variance") +##D K<-3 +##D set.seed(1) +##D Inits<-lapply(1:K,function(x){ModelInits()}) +##D +##D # running runMCMC_btadjust with MCMC_language="Jags": +##D set.seed(1) +##D out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, +##D data=ModelData, +##D Nchains=K, params=params, inits=Inits, +##D niter.min=1000, niter.max=300000, +##D nburnin.min=100, nburnin.max=200000, +##D thin.min=1, thin.max=1000, +##D neff.min=1000, conv.max=1.05, +##D control=list(print.diagnostics=TRUE, neff.method="Coda")) +##D +##D summary(out.mcmc.Coda) +## End(Not run) diff --git a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.Rout b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.Rout index 45b73671..24136c4e 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.Rout +++ b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.Rout @@ -1,7 +1,7 @@ -R version 4.3.2 (2023-10-31) -- "Eye Holes" -Copyright (C) 2023 The R Foundation for Statistical Computing -Platform: aarch64-apple-darwin20 (64-bit) +R version 4.4.2 (2024-10-31) -- "Pile of Leaves" +Copyright (C) 2024 The R Foundation for Statistical Computing +Platform: aarch64-apple-darwin20 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -25,6 +25,65 @@ Type 'q()' to quit R. > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() +> nameEx("findMCMC_strong_corrs") +> ### * findMCMC_strong_corrs +> +> flush(stderr()); flush(stdout()) +> +> ### Name: findMCMC_strong_corrs +> ### Title: findMCMC_strong_corrs +> ### Aliases: findMCMC_strong_corrs +> +> ### ** Examples +> +> ## Not run: +> ##D #generating data +> ##D set.seed(1) +> ##D y1000<-rnorm(n=1000,mean=600,sd=30) +> ##D ModelData <-list(mass = y1000,nobs = length(y1000)) +> ##D +> ##D #writing the Jags code as a character chain in R +> ##D modeltotransfer<-"model { +> ##D +> ##D # Priors +> ##D population.mean ~ dunif(0,5000) +> ##D population.sd ~ dunif(0,100) +> ##D +> ##D # Precision = 1/variance: Normal distribution parameterized by precision in Jags +> ##D population.variance <- population.sd * population.sd +> ##D precision <- 1 / population.variance +> ##D +> ##D # Likelihood +> ##D for(i in 1:nobs){ +> ##D mass[i] ~ dnorm(population.mean, precision) +> ##D } +> ##D }" +> ##D +> ##D #specifying the initial values +> ##D ModelInits <- function() +> ##D {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} +> ##D params <- c("population.mean", "population.sd", "population.variance") +> ##D K<-3 +> ##D set.seed(1) +> ##D Inits<-lapply(1:K,function(x){ModelInits()}) +> ##D +> ##D # running runMCMC_btadjust with MCMC_language="Jags": +> ##D set.seed(1) +> ##D out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, +> ##D data=ModelData, +> ##D Nchains=K, params=params, inits=Inits, +> ##D niter.min=1000, niter.max=300000, +> ##D nburnin.min=100, nburnin.max=200000, +> ##D thin.min=1, thin.max=1000, +> ##D neff.min=1000, conv.max=1.05, +> ##D control=list(print.diagnostics=TRUE, neff.method="Coda")) +> ##D +> ##D findMCMC_strong_corrs(out.mcmc.Coda) +> ## End(Not run) +> +> +> +> cleanEx() > nameEx("runMCMC_btadjust") > ### * runMCMC_btadjust > @@ -36,111 +95,51 @@ Type 'q()' to quit R. > > ### ** Examples > -> #\code{ -> # for examples with Nimble or Greta, see the Vignette. -> # condition variable of whether installation is OK with Jags to avoid error durong package check -> condition_jags<-TRUE -> if (nchar(system.file(package='rjags'))==0) {condition_jags<-FALSE} -> if (nchar(system.file(package='runjags'))==0) {condition_jags<-FALSE} -> if (condition_jags) -+ {suppressWarnings(temp<-runjags::testjags(silent=TRUE)) -+ if(!(temp$JAGS.available&temp$JAGS.found&temp$JAGS.major==4)) {condition_jags<-FALSE}} -> -> if (condition_jags) { -+ #generating data -+ set.seed(1) -+ y1000<-rnorm(n=1000,mean=600,sd=30) -+ ModelData <-list(mass = y1000,nobs = length(y1000)) -+ -+ #writing the Jags code as a character chain in R -+ modeltotransfer<-"model { -+ -+ # Priors -+ population.mean ~ dunif(0,5000) -+ population.sd ~ dunif(0,100) -+ -+ # Precision = 1/variance: Normal distribution parameterized by precision in Jags -+ population.variance <- population.sd * population.sd -+ precision <- 1 / population.variance -+ -+ # Likelihood -+ for(i in 1:nobs){ -+ mass[i] ~ dnorm(population.mean, precision) -+ } -+ }" -+ -+ #specifying the initial values -+ ModelInits <- function() -+ {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} -+ params <- c("population.mean", "population.sd", "population.variance") -+ K<-3 -+ set.seed(1) -+ Inits<-lapply(1:K,function(x){ModelInits()}) -+ -+ # running runMCMC_btadjust with MCMC_language="Jags": -+ set.seed(1) -+ out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, -+ data=ModelData, -+ Nchains=K, params=params, inits=Inits, -+ niter.min=1000, niter.max=300000, -+ nburnin.min=100, nburnin.max=200000, -+ thin.min=1, thin.max=1000, -+ neff.min=1000, conv.max=1.05, -+ control=list(print.diagnostics=TRUE, neff.method="Coda")) -+ -+ summary(out.mcmc.Coda) -+ } -Compiling model graph - Resolving undeclared variables - Allocating nodes -Graph information: - Observed stochastic nodes: 1000 - Unobserved stochastic nodes: 2 - Total graph size: 1009 - -Initializing model - -Cycle 1... -[1] "###################################################################################" -[1] "###################################################################################" -[1] "Current state of diagnostics:" - Nchains thin niter.tot Nvalues nu.burn -MCMC parameters 3 1 1000 2700 1 -[1] "###################################################################################" - max median mean name_max prop_ab_1p2 prop_ab_1p05 -Gelman_Upper_C_I 1 1 1 population.sd 0 0 -Gelman_Point_Est 1 1 1 population.sd 0 0 - prop_ab_1p01 -Gelman_Upper_C_I 0 -Gelman_Point_Est 0 -[1] "###################################################################################" - min median mean name_min prop_bel_1000 prop_bel_5000 -Neff 1615 1787 1732 population.mean 0 1 - prop_bel_10000 -Neff 1 -[1] "###################################################################################" - -Iterations = 1:900 -Thinning interval = 1 -Number of chains = 3 -Sample size per chain = 900 - -1. Empirical mean and standard deviation for each variable, - plus standard error of the mean: - - Mean SD Naive SE Time-series SE -population.mean 599.65 0.9868 0.01899 0.02478 -population.sd 31.08 0.6971 0.01342 0.01649 -population.variance 966.42 43.4011 0.83525 1.02801 - -2. Quantiles for each variable: - - 2.5% 25% 50% 75% 97.5% -population.mean 597.77 599.0 599.63 600.29 601.55 -population.sd 29.74 30.6 31.07 31.56 32.46 -population.variance 884.27 936.2 965.16 996.12 1053.78 - -> #} +> # for examples with Nimble or Greta, see the Presentation Vignette. +> ## Not run: +> ##D #generating data +> ##D set.seed(1) +> ##D y1000<-rnorm(n=1000,mean=600,sd=30) +> ##D ModelData <-list(mass = y1000,nobs = length(y1000)) +> ##D +> ##D #writing the Jags code as a character chain in R +> ##D modeltotransfer<-"model { +> ##D +> ##D # Priors +> ##D population.mean ~ dunif(0,5000) +> ##D population.sd ~ dunif(0,100) +> ##D +> ##D # Precision = 1/variance: Normal distribution parameterized by precision in Jags +> ##D population.variance <- population.sd * population.sd +> ##D precision <- 1 / population.variance +> ##D +> ##D # Likelihood +> ##D for(i in 1:nobs){ +> ##D mass[i] ~ dnorm(population.mean, precision) +> ##D } +> ##D }" +> ##D +> ##D #specifying the initial values +> ##D ModelInits <- function() +> ##D {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} +> ##D params <- c("population.mean", "population.sd", "population.variance") +> ##D K<-3 +> ##D set.seed(1) +> ##D Inits<-lapply(1:K,function(x){ModelInits()}) +> ##D +> ##D # running runMCMC_btadjust with MCMC_language="Jags": +> ##D set.seed(1) +> ##D out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, +> ##D data=ModelData, +> ##D Nchains=K, params=params, inits=Inits, +> ##D niter.min=1000, niter.max=300000, +> ##D nburnin.min=100, nburnin.max=200000, +> ##D thin.min=1, thin.max=1000, +> ##D neff.min=1000, conv.max=1.05, +> ##D control=list(print.diagnostics=TRUE, neff.method="Coda")) +> ##D +> ##D summary(out.mcmc.Coda) +> ## End(Not run) > > > @@ -149,7 +148,7 @@ population.variance 884.27 936.2 965.16 996.12 1053.78 > cleanEx() > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 1.415 0.03 1.506 0.017 0.022 +Time elapsed: 0.036 0.003 0.04 0 0 > grDevices::dev.off() null device 1 diff --git a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/tests/testthat.Rout b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/tests/testthat.Rout index 17dd8e1d..b45fd22a 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/tests/testthat.Rout +++ b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/tests/testthat.Rout @@ -1,7 +1,7 @@ -R version 4.3.2 (2023-10-31) -- "Eye Holes" -Copyright (C) 2023 The R Foundation for Statistical Computing -Platform: aarch64-apple-darwin20 (64-bit) +R version 4.4.2 (2024-10-31) -- "Pile of Leaves" +Copyright (C) 2024 The R Foundation for Statistical Computing +Platform: aarch64-apple-darwin20 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -27,7 +27,7 @@ Type 'q()' to quit R. > library(runMCMCbtadjust) > > test_check("runMCMCbtadjust") -nimble version 1.0.1 is loaded. +nimble version 1.2.1 is loaded. For more information on NIMBLE and a User Manual, please visit https://R-nimble.org. @@ -42,32 +42,43 @@ The following object is masked from 'package:stats': simulate -Timing stopped at: 0.004 0 0.005 -Timing stopped at: 0.003 0 0.004 -Timing stopped at: 0.004 0 0.004 -Timing stopped at: 0.002 0 0.002 -Timing stopped at: 0.004 0 0.004 -Timing stopped at: 0.004 0 0.004 -Timing stopped at: 0.005 0 0.006 -Timing stopped at: 0.002 0 0.002 -Timing stopped at: 0.003 0 0.003 +The following object is masked from 'package:base': + + declare + +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.005 0 0.005 Timing stopped at: 0.002 0 0.002 +Timing stopped at: 0.003 0 0.002 Timing stopped at: 0.002 0 0.003 Timing stopped at: 0.002 0 0.003 Timing stopped at: 0.002 0 0.002 +Timing stopped at: 0.003 0 0.003 +Timing stopped at: 0.003 0 0.003 +Timing stopped at: 0.003 0 0.002 +Timing stopped at: 0.003 0 0.002 Timing stopped at: 0.002 0 0.003 Timing stopped at: 0.003 0 0.003 -Timing stopped at: 0.003 0 0.004 +Timing stopped at: 0.002 0 0.003 +Timing stopped at: 0.003 0 0.002 +Timing stopped at: 0.002 0 0.002 +Timing stopped at: 0.003 0 0.002 +[1] "control$seed is NULL. Replaced by 1" Timing stopped at: 0.004 0 0.005 -Timing stopped at: 0.003 0 0.004 -Timing stopped at: 0.004 0.001 0.006 -Timing stopped at: 0.005 0.001 0.005 +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.004 0.001 0.004 +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.004 0 0.004 +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.007 0.001 0.012 +[1] "control$seed is NULL. Replaced by 1" Timing stopped at: 0.004 0.001 0.005 -Timing stopped at: 0.004 0 0.005 -[ FAIL 0 | WARN 1 | SKIP 0 | PASS 23 ] +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.007 0.001 0.008 +[ FAIL 0 | WARN 2 | SKIP 0 | PASS 23 ] -[ FAIL 0 | WARN 1 | SKIP 0 | PASS 23 ] +[ FAIL 0 | WARN 2 | SKIP 0 | PASS 23 ] > > proc.time() user system elapsed - 2.619 0.085 2.729 + 2.556 0.065 2.664 diff --git a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/tests/testthat/test-runMCMC_btadjust.R b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/tests/testthat/test-runMCMC_btadjust.R index e12b9a73..54fd4b58 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/tests/testthat/test-runMCMC_btadjust.R +++ b/revdep/checks.noindex/runMCMCbtadjust/new/runMCMCbtadjust.Rcheck/tests/testthat/test-runMCMC_btadjust.R @@ -1,4 +1,4 @@ -context("tunMCMC_btadjust") +context("runMCMC_btadjust") ### minimal setup for running runMCMC_btadjust: see vignette set.seed(1) @@ -135,7 +135,7 @@ testthat::test_that("errors", { inits=Inits,params=params,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000,control=list(convType="Gelman",convtype.alpha=NULL)))) testthat::expect_error((runMCMC_btadjust(data=ModelData,constants=ModelConsts,code=ModelCode,MCMC_language="Nimble", inits=Inits,params=params,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000,control=list(convType="Gelman",convtype.alpha=1.1)))) - + #should give an error because neff.method is not "Stan" or "Coda" testthat::expect_error((runMCMC_btadjust(data=ModelData,constants=ModelConsts,code=ModelCode,MCMC_language="Nimble", @@ -167,6 +167,7 @@ testthat::test_that("errors", { inits=Inits,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000))) + })} @@ -183,7 +184,7 @@ testthat::test_that("errors", { testthat::expect_error((runMCMC_btadjust(data=ModelData.Jags,MCMC_language="Jags", inits=Inits,params=params,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000))) - + #should give an error because code is not of type character with MCMC_language="Jags" testthat::expect_error((runMCMC_btadjust(data=ModelData.Jags,code=1,MCMC_language="Jags", inits=Inits,params=params,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000))) diff --git a/revdep/checks.noindex/runMCMCbtadjust/old/libraries.txt b/revdep/checks.noindex/runMCMCbtadjust/old/libraries.txt index 57e7707d..811f0443 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/old/libraries.txt +++ b/revdep/checks.noindex/runMCMCbtadjust/old/libraries.txt @@ -1,123 +1,180 @@ Library: /Users/nick/github/greta-dev/greta/revdep/library.noindex/greta/old -greta (0.4.3) +abind (1.4-8) +backports (1.5.0) +base64enc (0.1-3) +callr (3.7.6) +cli (3.6.3) +coda (0.19-4.1) +config (0.3.2) +crayon (1.5.3) +digest (0.6.37) +future (1.34.0) +globals (0.16.3) +glue (1.8.0) +greta (0.4.5) +here (1.0.1) +hms (1.1.3) +jsonlite (1.8.9) +lifecycle (1.0.4) +listenv (0.9.1) +magrittr (2.0.3) +parallelly (1.38.0) +pkgconfig (2.0.3) +png (0.1-8) +prettyunits (1.2.0) +processx (3.8.4) +progress (1.2.3) +ps (1.8.1) +R6 (2.5.1) +rappdirs (0.3.3) +Rcpp (1.0.13-1) +RcppTOML (0.2.2) +reticulate (1.39.0) +rlang (1.1.4) +rprojroot (2.0.4) +rstudioapi (0.17.1) +tensorflow (2.16.0) +tfautograph (0.3.2) +tfruns (1.5.3) +tidyselect (1.2.1) +vctrs (0.6.5) +whisker (0.4.1) +withr (3.0.2) +yaml (2.3.10) +yesno (0.1.3) Library: /Users/nick/github/greta-dev/greta/revdep/library.noindex/runMCMCbtadjust -abind (1.4-5) -backports (1.4.1) -base64enc (0.1-3) -BH (1.84.0-0) -bit (4.0.5) -bit64 (4.0.5) -brio (1.1.4) -broom (1.0.5) -broom.helpers (1.14.0) -callr (3.7.3) -checkmate (2.3.1) -cli (3.6.2) -clipr (0.8.0) -coda (0.19-4) -codetools (0.2-19) -colorspace (2.1-0) -commonmark (1.9.0) -config (0.3.2) -cpp11 (0.4.7) -crayon (1.5.2) -desc (1.4.3) -diffobj (0.3.5) -digest (0.6.34) -dplyr (1.1.4) -ellipsis (0.3.2) -evaluate (0.23) -fansi (1.0.6) -farver (2.1.1) -forcats (1.0.0) -fs (1.6.3) -future (1.33.1) -generics (0.1.3) -GGally (2.2.0) -ggmcmc (1.5.1.1) -ggplot2 (3.4.4) -ggstats (0.5.1) -globals (0.16.2) -glue (1.7.0) -gridExtra (2.3) -gtable (0.3.4) -haven (2.5.4) -here (1.0.1) -highr (0.10) -hms (1.1.3) -igraph (1.6.0) -inline (0.3.19) -isoband (0.2.7) -jsonlite (1.8.8) -knitr (1.45) -labeling (0.4.3) -labelled (2.12.0) -lattice (0.22-5) -lifecycle (1.0.4) -listenv (0.9.0) -loo (2.6.0) -magrittr (2.0.3) -markdown (1.12) -MASS (7.3-60.0.1) -Matrix (1.6-5) -matrixStats (1.2.0) -mgcv (1.9-1) -munsell (0.5.0) -nimble (1.0.1) -nlme (3.1-164) -numDeriv (2016.8-1.1) -parallelly (1.36.0) -patchwork (1.2.0) -pillar (1.9.0) -pkgbuild (1.4.3) -pkgconfig (2.0.3) -pkgload (1.3.3) -plyr (1.8.9) -png (0.1-8) -pracma (2.4.4) -praise (1.0.0) -prettyunits (1.2.0) -processx (3.8.3) -progress (1.2.3) -ps (1.7.5) -purrr (1.0.2) -QuickJSR (1.0.9) -R6 (2.5.1) -rappdirs (0.3.3) -RColorBrewer (1.1-3) -Rcpp (1.0.12) -RcppEigen (0.3.3.9.4) -RcppParallel (5.1.7) -RcppTOML (0.2.2) -readr (2.1.5) -rematch2 (2.1.2) -reticulate (1.34.0) -rjags (4-15) -rlang (1.1.3) -rprojroot (2.0.4) -rstan (2.32.5) -rstudioapi (0.15.0) -runjags (2.2.2-1.1) -scales (1.3.0) -StanHeaders (2.32.5) -stringi (1.8.3) -stringr (1.5.1) -tensorflow (2.14.0) -testthat (3.2.1) -tfautograph (0.3.2) -tfruns (1.5.1) -tibble (3.2.1) -tidyr (1.3.0) -tidyselect (1.2.0) -tzdb (0.4.0) -utf8 (1.2.4) -vctrs (0.6.5) -viridisLite (0.4.2) -vroom (1.6.5) -waldo (0.5.2) -whisker (0.4.1) -withr (2.5.2) -xfun (0.41) -yaml (2.3.8) -yesno (0.1.2) +abind (1.4-8) +backports (1.5.0) +base64enc (0.1-3) +BH (1.84.0-0) +brio (1.1.5) +bslib (0.8.0) +cachem (1.1.0) +callr (3.7.6) +checkmate (2.3.2) +cli (3.6.3) +cluster (2.1.6) +coda (0.19-4.1) +codetools (0.2-20) +colorspace (2.1-1) +commonmark (1.9.2) +config (0.3.2) +cpp11 (0.5.0) +crayon (1.5.3) +data.table (1.16.2) +desc (1.4.3) +diffobj (0.3.5) +digest (0.6.37) +distributional (0.5.0) +dplyr (1.1.4) +evaluate (1.0.1) +fansi (1.0.6) +farver (2.1.2) +fastmap (1.2.0) +fontawesome (0.5.2) +forcats (1.0.0) +foreign (0.8-87) +Formula (1.2-5) +fs (1.6.5) +future (1.34.0) +generics (0.1.3) +GGally (2.2.1) +ggmcmc (1.5.1.1) +ggplot2 (3.5.1) +ggstats (0.7.0) +globals (0.16.3) +glue (1.8.0) +gridExtra (2.3) +gtable (0.3.6) +here (1.0.1) +highr (0.11) +Hmisc (5.2-0) +hms (1.1.3) +htmlTable (2.4.3) +htmltools (0.5.8.1) +htmlwidgets (1.6.4) +igraph (2.1.1) +inline (0.3.19) +isoband (0.2.7) +jquerylib (0.1.4) +jsonlite (1.8.9) +knitr (1.48) +labeling (0.4.3) +lattice (0.22-6) +lifecycle (1.0.4) +listenv (0.9.1) +loo (2.8.0) +magrittr (2.0.3) +markdown (1.13) +MASS (7.3-61) +Matrix (1.7-1) +matrixStats (1.4.1) +memoise (2.0.1) +mgcv (1.9-1) +mime (0.12) +moments (0.14.1) +munsell (0.5.1) +nimble (1.2.1) +nimbleAPT (1.0.6) +nimbleHMC (0.2.2) +nlme (3.1-166) +nnet (7.3-19) +numDeriv (2016.8-1.1) +parallelly (1.38.0) +patchwork (1.3.0) +pillar (1.9.0) +pkgbuild (1.4.5) +pkgconfig (2.0.3) +pkgload (1.4.0) +plyr (1.8.9) +png (0.1-8) +posterior (1.6.0) +pracma (2.4.4) +praise (1.0.0) +prettyunits (1.2.0) +processx (3.8.4) +progress (1.2.3) +ps (1.8.1) +purrr (1.0.2) +QuickJSR (1.4.0) +R6 (2.5.1) +rappdirs (0.3.3) +RColorBrewer (1.1-3) +Rcpp (1.0.13-1) +RcppEigen (0.3.4.0.2) +RcppParallel (5.1.9) +RcppTOML (0.2.2) +reticulate (1.39.0) +rjags (4-16) +rlang (1.1.4) +rmarkdown (2.29) +rpart (4.1.23) +rprojroot (2.0.4) +rstan (2.32.6) +rstudioapi (0.17.1) +runjags (2.2.2-4) +sass (0.4.9) +scales (1.3.0) +StanHeaders (2.32.10) +stringi (1.8.4) +stringr (1.5.1) +tensorA (0.36.2.1) +tensorflow (2.16.0) +testthat (3.2.1.1) +tfautograph (0.3.2) +tfruns (1.5.3) +tibble (3.2.1) +tidyr (1.3.1) +tidyselect (1.2.1) +tinytex (0.54) +utf8 (1.2.4) +vctrs (0.6.5) +viridis (0.6.5) +viridisLite (0.4.2) +waldo (0.6.0) +whisker (0.4.1) +withr (3.0.2) +xfun (0.49) +yaml (2.3.10) +yesno (0.1.3) diff --git a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/00check.log b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/00check.log index 8bdac30b..2872b838 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/00check.log +++ b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/00check.log @@ -1,15 +1,15 @@ * using log directory ‘/Users/nick/github/greta-dev/greta/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck’ -* using R version 4.3.2 (2023-10-31) -* using platform: aarch64-apple-darwin20 (64-bit) +* using R version 4.4.2 (2024-10-31) +* using platform: aarch64-apple-darwin20 * R was compiled by Apple clang version 14.0.0 (clang-1400.0.29.202) GNU Fortran (GCC) 12.2.0 -* running under: macOS Sonoma 14.0 +* running under: macOS Sonoma 14.5 * using session charset: UTF-8 * using options ‘--no-manual --no-build-vignettes’ * checking for file ‘runMCMCbtadjust/DESCRIPTION’ ... OK * checking extension type ... Package -* this is package ‘runMCMCbtadjust’ version ‘1.0.5’ +* this is package ‘runMCMCbtadjust’ version ‘1.1.2’ * package encoding: UTF-8 * checking package namespace information ... OK * checking package dependencies ... OK @@ -23,15 +23,12 @@ * checking installed package size ... OK * checking package directory ... OK * checking ‘build’ directory ... OK -* checking DESCRIPTION meta-information ... WARNING -Non-standard license specification: - CECILL-2.1 -Standardizable: FALSE +* checking DESCRIPTION meta-information ... OK * checking top-level files ... OK * checking for left-over files ... OK * checking index information ... OK * checking package subdirectories ... OK -* checking R files for non-ASCII characters ... OK +* checking code files for non-ASCII characters ... OK * checking R files for syntax errors ... OK * checking whether the package can be loaded ... OK * checking whether the package can be loaded with stated dependencies ... OK @@ -39,7 +36,11 @@ Standardizable: FALSE * checking whether the namespace can be loaded with stated dependencies ... OK * checking whether the namespace can be unloaded cleanly ... OK * checking loading without being on the library search path ... OK -* checking dependencies in R code ... OK +* checking dependencies in R code ... NOTE +'library' or 'require' calls in package code: + ‘nimble’ ‘nimbleAPT’ + Please use :: or requireNamespace() instead. + See section 'Suggested packages' in the 'Writing R Extensions' manual. * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK @@ -59,9 +60,11 @@ Standardizable: FALSE * checking tests ... OK Running ‘testthat.R’ * checking for unstated dependencies in vignettes ... OK -* checking package vignettes in ‘inst/doc’ ... OK +* checking package vignettes ... OK * checking running R code from vignettes ... NONE - ‘runMCMCbtadjust_Presentation.Rmd’ using ‘UTF-8’... OK + ‘runMCMCbtadjust_Nimble_variations.Rmd’ using ‘UTF-8’... OK + ‘runMCMCbtadjust_Pres.Rmd’ using ‘UTF-8’... OK + ‘runMCMCbtadjust_extraCalculations.Rmd’ using ‘UTF-8’... OK * checking re-building of vignette outputs ... SKIPPED * DONE -Status: 1 WARNING +Status: 1 NOTE diff --git a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/00install.out b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/00install.out index 173f6d8a..16cb286f 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/00install.out +++ b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/00install.out @@ -6,6 +6,7 @@ ** byte-compile and prepare package for lazy loading ** help *** installing help indices +*** copying figures ** building package indices ** installing vignettes ** testing if installed package can be loaded from temporary location diff --git a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.R b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.R index ece014bd..05b5a58c 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.R +++ b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.R @@ -6,72 +6,121 @@ library('runMCMCbtadjust') base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') cleanEx() -nameEx("runMCMC_btadjust") -### * runMCMC_btadjust +nameEx("findMCMC_strong_corrs") +### * findMCMC_strong_corrs flush(stderr()); flush(stdout()) -### Name: runMCMC_btadjust -### Title: runMCMC_btadjust -### Aliases: runMCMC_btadjust +### Name: findMCMC_strong_corrs +### Title: findMCMC_strong_corrs +### Aliases: findMCMC_strong_corrs ### ** Examples - #\code{ -# for examples with Nimble or Greta, see the Vignette. -# condition variable of whether installation is OK with Jags to avoid error durong package check -condition_jags<-TRUE -if (nchar(system.file(package='rjags'))==0) {condition_jags<-FALSE} -if (nchar(system.file(package='runjags'))==0) {condition_jags<-FALSE} -if (condition_jags) -{suppressWarnings(temp<-runjags::testjags(silent=TRUE)) - if(!(temp$JAGS.available&temp$JAGS.found&temp$JAGS.major==4)) {condition_jags<-FALSE}} - -if (condition_jags) { -#generating data -set.seed(1) -y1000<-rnorm(n=1000,mean=600,sd=30) -ModelData <-list(mass = y1000,nobs = length(y1000)) +## Not run: +##D #generating data +##D set.seed(1) +##D y1000<-rnorm(n=1000,mean=600,sd=30) +##D ModelData <-list(mass = y1000,nobs = length(y1000)) +##D +##D #writing the Jags code as a character chain in R +##D modeltotransfer<-"model { +##D +##D # Priors +##D population.mean ~ dunif(0,5000) +##D population.sd ~ dunif(0,100) +##D +##D # Precision = 1/variance: Normal distribution parameterized by precision in Jags +##D population.variance <- population.sd * population.sd +##D precision <- 1 / population.variance +##D +##D # Likelihood +##D for(i in 1:nobs){ +##D mass[i] ~ dnorm(population.mean, precision) +##D } +##D }" +##D +##D #specifying the initial values +##D ModelInits <- function() +##D {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} +##D params <- c("population.mean", "population.sd", "population.variance") +##D K<-3 +##D set.seed(1) +##D Inits<-lapply(1:K,function(x){ModelInits()}) +##D +##D # running runMCMC_btadjust with MCMC_language="Jags": +##D set.seed(1) +##D out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, +##D data=ModelData, +##D Nchains=K, params=params, inits=Inits, +##D niter.min=1000, niter.max=300000, +##D nburnin.min=100, nburnin.max=200000, +##D thin.min=1, thin.max=1000, +##D neff.min=1000, conv.max=1.05, +##D control=list(print.diagnostics=TRUE, neff.method="Coda")) +##D +##D findMCMC_strong_corrs(out.mcmc.Coda) +## End(Not run) -#writing the Jags code as a character chain in R -modeltotransfer<-"model { -# Priors -population.mean ~ dunif(0,5000) -population.sd ~ dunif(0,100) -# Precision = 1/variance: Normal distribution parameterized by precision in Jags -population.variance <- population.sd * population.sd -precision <- 1 / population.variance +cleanEx() +nameEx("runMCMC_btadjust") +### * runMCMC_btadjust -# Likelihood -for(i in 1:nobs){ - mass[i] ~ dnorm(population.mean, precision) - } - }" +flush(stderr()); flush(stdout()) -#specifying the initial values -ModelInits <- function() -{list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} -params <- c("population.mean", "population.sd", "population.variance") -K<-3 -set.seed(1) -Inits<-lapply(1:K,function(x){ModelInits()}) +### Name: runMCMC_btadjust +### Title: runMCMC_btadjust +### Aliases: runMCMC_btadjust -# running runMCMC_btadjust with MCMC_language="Jags": -set.seed(1) -out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, -data=ModelData, -Nchains=K, params=params, inits=Inits, -niter.min=1000, niter.max=300000, -nburnin.min=100, nburnin.max=200000, -thin.min=1, thin.max=1000, -neff.min=1000, conv.max=1.05, -control=list(print.diagnostics=TRUE, neff.method="Coda")) +### ** Examples -summary(out.mcmc.Coda) -} -#} +# for examples with Nimble or Greta, see the Presentation Vignette. +## Not run: +##D #generating data +##D set.seed(1) +##D y1000<-rnorm(n=1000,mean=600,sd=30) +##D ModelData <-list(mass = y1000,nobs = length(y1000)) +##D +##D #writing the Jags code as a character chain in R +##D modeltotransfer<-"model { +##D +##D # Priors +##D population.mean ~ dunif(0,5000) +##D population.sd ~ dunif(0,100) +##D +##D # Precision = 1/variance: Normal distribution parameterized by precision in Jags +##D population.variance <- population.sd * population.sd +##D precision <- 1 / population.variance +##D +##D # Likelihood +##D for(i in 1:nobs){ +##D mass[i] ~ dnorm(population.mean, precision) +##D } +##D }" +##D +##D #specifying the initial values +##D ModelInits <- function() +##D {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} +##D params <- c("population.mean", "population.sd", "population.variance") +##D K<-3 +##D set.seed(1) +##D Inits<-lapply(1:K,function(x){ModelInits()}) +##D +##D # running runMCMC_btadjust with MCMC_language="Jags": +##D set.seed(1) +##D out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, +##D data=ModelData, +##D Nchains=K, params=params, inits=Inits, +##D niter.min=1000, niter.max=300000, +##D nburnin.min=100, nburnin.max=200000, +##D thin.min=1, thin.max=1000, +##D neff.min=1000, conv.max=1.05, +##D control=list(print.diagnostics=TRUE, neff.method="Coda")) +##D +##D summary(out.mcmc.Coda) +## End(Not run) diff --git a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.Rout b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.Rout index 516ebe79..df945283 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.Rout +++ b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/runMCMCbtadjust-Ex.Rout @@ -1,7 +1,7 @@ -R version 4.3.2 (2023-10-31) -- "Eye Holes" -Copyright (C) 2023 The R Foundation for Statistical Computing -Platform: aarch64-apple-darwin20 (64-bit) +R version 4.4.2 (2024-10-31) -- "Pile of Leaves" +Copyright (C) 2024 The R Foundation for Statistical Computing +Platform: aarch64-apple-darwin20 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -25,6 +25,65 @@ Type 'q()' to quit R. > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() +> nameEx("findMCMC_strong_corrs") +> ### * findMCMC_strong_corrs +> +> flush(stderr()); flush(stdout()) +> +> ### Name: findMCMC_strong_corrs +> ### Title: findMCMC_strong_corrs +> ### Aliases: findMCMC_strong_corrs +> +> ### ** Examples +> +> ## Not run: +> ##D #generating data +> ##D set.seed(1) +> ##D y1000<-rnorm(n=1000,mean=600,sd=30) +> ##D ModelData <-list(mass = y1000,nobs = length(y1000)) +> ##D +> ##D #writing the Jags code as a character chain in R +> ##D modeltotransfer<-"model { +> ##D +> ##D # Priors +> ##D population.mean ~ dunif(0,5000) +> ##D population.sd ~ dunif(0,100) +> ##D +> ##D # Precision = 1/variance: Normal distribution parameterized by precision in Jags +> ##D population.variance <- population.sd * population.sd +> ##D precision <- 1 / population.variance +> ##D +> ##D # Likelihood +> ##D for(i in 1:nobs){ +> ##D mass[i] ~ dnorm(population.mean, precision) +> ##D } +> ##D }" +> ##D +> ##D #specifying the initial values +> ##D ModelInits <- function() +> ##D {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} +> ##D params <- c("population.mean", "population.sd", "population.variance") +> ##D K<-3 +> ##D set.seed(1) +> ##D Inits<-lapply(1:K,function(x){ModelInits()}) +> ##D +> ##D # running runMCMC_btadjust with MCMC_language="Jags": +> ##D set.seed(1) +> ##D out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, +> ##D data=ModelData, +> ##D Nchains=K, params=params, inits=Inits, +> ##D niter.min=1000, niter.max=300000, +> ##D nburnin.min=100, nburnin.max=200000, +> ##D thin.min=1, thin.max=1000, +> ##D neff.min=1000, conv.max=1.05, +> ##D control=list(print.diagnostics=TRUE, neff.method="Coda")) +> ##D +> ##D findMCMC_strong_corrs(out.mcmc.Coda) +> ## End(Not run) +> +> +> +> cleanEx() > nameEx("runMCMC_btadjust") > ### * runMCMC_btadjust > @@ -36,111 +95,51 @@ Type 'q()' to quit R. > > ### ** Examples > -> #\code{ -> # for examples with Nimble or Greta, see the Vignette. -> # condition variable of whether installation is OK with Jags to avoid error durong package check -> condition_jags<-TRUE -> if (nchar(system.file(package='rjags'))==0) {condition_jags<-FALSE} -> if (nchar(system.file(package='runjags'))==0) {condition_jags<-FALSE} -> if (condition_jags) -+ {suppressWarnings(temp<-runjags::testjags(silent=TRUE)) -+ if(!(temp$JAGS.available&temp$JAGS.found&temp$JAGS.major==4)) {condition_jags<-FALSE}} -> -> if (condition_jags) { -+ #generating data -+ set.seed(1) -+ y1000<-rnorm(n=1000,mean=600,sd=30) -+ ModelData <-list(mass = y1000,nobs = length(y1000)) -+ -+ #writing the Jags code as a character chain in R -+ modeltotransfer<-"model { -+ -+ # Priors -+ population.mean ~ dunif(0,5000) -+ population.sd ~ dunif(0,100) -+ -+ # Precision = 1/variance: Normal distribution parameterized by precision in Jags -+ population.variance <- population.sd * population.sd -+ precision <- 1 / population.variance -+ -+ # Likelihood -+ for(i in 1:nobs){ -+ mass[i] ~ dnorm(population.mean, precision) -+ } -+ }" -+ -+ #specifying the initial values -+ ModelInits <- function() -+ {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} -+ params <- c("population.mean", "population.sd", "population.variance") -+ K<-3 -+ set.seed(1) -+ Inits<-lapply(1:K,function(x){ModelInits()}) -+ -+ # running runMCMC_btadjust with MCMC_language="Jags": -+ set.seed(1) -+ out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, -+ data=ModelData, -+ Nchains=K, params=params, inits=Inits, -+ niter.min=1000, niter.max=300000, -+ nburnin.min=100, nburnin.max=200000, -+ thin.min=1, thin.max=1000, -+ neff.min=1000, conv.max=1.05, -+ control=list(print.diagnostics=TRUE, neff.method="Coda")) -+ -+ summary(out.mcmc.Coda) -+ } -Compiling model graph - Resolving undeclared variables - Allocating nodes -Graph information: - Observed stochastic nodes: 1000 - Unobserved stochastic nodes: 2 - Total graph size: 1009 - -Initializing model - -Cycle 1... -[1] "###################################################################################" -[1] "###################################################################################" -[1] "Current state of diagnostics:" - Nchains thin niter.tot Nvalues nu.burn -MCMC parameters 3 1 1000 2700 1 -[1] "###################################################################################" - max median mean name_max prop_ab_1p2 prop_ab_1p05 -Gelman_Upper_C_I 1.001 1.001 1.001 population.mean 0 0 -Gelman_Point_Est 1.000 1.000 1.000 population.mean 0 0 - prop_ab_1p01 -Gelman_Upper_C_I 0 -Gelman_Point_Est 0 -[1] "###################################################################################" - min median mean name_min prop_bel_1000 -Neff 1773 1778 1787 population.variance 0 - prop_bel_5000 prop_bel_10000 -Neff 1 1 -[1] "###################################################################################" - -Iterations = 1:900 -Thinning interval = 1 -Number of chains = 3 -Sample size per chain = 900 - -1. Empirical mean and standard deviation for each variable, - plus standard error of the mean: - - Mean SD Naive SE Time-series SE -population.mean 599.67 0.9941 0.01913 0.02344 -population.sd 31.07 0.6850 0.01318 0.01633 -population.variance 965.96 42.6060 0.81995 1.01695 - -2. Quantiles for each variable: - - 2.5% 25% 50% 75% 97.5% -population.mean 597.70 598.99 599.66 600.35 601.57 -population.sd 29.76 30.59 31.07 31.53 32.42 -population.variance 885.53 935.97 965.40 994.14 1051.32 - -> #} +> # for examples with Nimble or Greta, see the Presentation Vignette. +> ## Not run: +> ##D #generating data +> ##D set.seed(1) +> ##D y1000<-rnorm(n=1000,mean=600,sd=30) +> ##D ModelData <-list(mass = y1000,nobs = length(y1000)) +> ##D +> ##D #writing the Jags code as a character chain in R +> ##D modeltotransfer<-"model { +> ##D +> ##D # Priors +> ##D population.mean ~ dunif(0,5000) +> ##D population.sd ~ dunif(0,100) +> ##D +> ##D # Precision = 1/variance: Normal distribution parameterized by precision in Jags +> ##D population.variance <- population.sd * population.sd +> ##D precision <- 1 / population.variance +> ##D +> ##D # Likelihood +> ##D for(i in 1:nobs){ +> ##D mass[i] ~ dnorm(population.mean, precision) +> ##D } +> ##D }" +> ##D +> ##D #specifying the initial values +> ##D ModelInits <- function() +> ##D {list (population.mean = rnorm(1,600,90), population.sd = runif(1, 1, 30))} +> ##D params <- c("population.mean", "population.sd", "population.variance") +> ##D K<-3 +> ##D set.seed(1) +> ##D Inits<-lapply(1:K,function(x){ModelInits()}) +> ##D +> ##D # running runMCMC_btadjust with MCMC_language="Jags": +> ##D set.seed(1) +> ##D out.mcmc.Coda<-runMCMC_btadjust(MCMC_language="Jags", code=modeltotransfer, +> ##D data=ModelData, +> ##D Nchains=K, params=params, inits=Inits, +> ##D niter.min=1000, niter.max=300000, +> ##D nburnin.min=100, nburnin.max=200000, +> ##D thin.min=1, thin.max=1000, +> ##D neff.min=1000, conv.max=1.05, +> ##D control=list(print.diagnostics=TRUE, neff.method="Coda")) +> ##D +> ##D summary(out.mcmc.Coda) +> ## End(Not run) > > > @@ -149,7 +148,7 @@ population.variance 885.53 935.97 965.40 994.14 1051.32 > cleanEx() > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 1.481 0.042 15.239 0.021 0.035 +Time elapsed: 0.035 0.003 0.041 0 0 > grDevices::dev.off() null device 1 diff --git a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/tests/testthat.Rout b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/tests/testthat.Rout index bc3aaa3d..29f60329 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/tests/testthat.Rout +++ b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/tests/testthat.Rout @@ -1,7 +1,7 @@ -R version 4.3.2 (2023-10-31) -- "Eye Holes" -Copyright (C) 2023 The R Foundation for Statistical Computing -Platform: aarch64-apple-darwin20 (64-bit) +R version 4.4.2 (2024-10-31) -- "Pile of Leaves" +Copyright (C) 2024 The R Foundation for Statistical Computing +Platform: aarch64-apple-darwin20 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -27,7 +27,7 @@ Type 'q()' to quit R. > library(runMCMCbtadjust) > > test_check("runMCMCbtadjust") -nimble version 1.0.1 is loaded. +nimble version 1.2.1 is loaded. For more information on NIMBLE and a User Manual, please visit https://R-nimble.org. @@ -42,32 +42,43 @@ The following object is masked from 'package:stats': simulate -Timing stopped at: 0.004 0 0.004 -Timing stopped at: 0.004 0 0.005 -Timing stopped at: 0.005 0 0.005 +The following object is masked from 'package:base': + + declare + +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.004 0.001 0.006 +Timing stopped at: 0.003 0 0.003 +Timing stopped at: 0.003 0 0.003 Timing stopped at: 0.002 0 0.002 -Timing stopped at: 0.004 0 0.005 -Timing stopped at: 0.005 0 0.006 -Timing stopped at: 0.004 0 0.004 Timing stopped at: 0.003 0 0.002 -Timing stopped at: 0.002 0 0.002 Timing stopped at: 0.003 0 0.002 -Timing stopped at: 0.002 0 0.002 Timing stopped at: 0.003 0 0.003 +Timing stopped at: 0.003 0 0.003 +Timing stopped at: 0.003 0 0.002 Timing stopped at: 0.002 0 0.003 Timing stopped at: 0.002 0 0.003 +Timing stopped at: 0.003 0.001 0.003 +Timing stopped at: 0.004 0.001 0.01 +Timing stopped at: 0.003 0 0.002 Timing stopped at: 0.003 0 0.003 -Timing stopped at: 0.004 0 0.004 -Timing stopped at: 0.004 0 0.004 -Timing stopped at: 0.005 0.001 0.005 -Timing stopped at: 0.005 0 0.005 +Timing stopped at: 0.003 0 0.003 +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.004 0.001 0.004 +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.005 0 0.007 +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.004 0 0.005 +[1] "control$seed is NULL. Replaced by 1" Timing stopped at: 0.004 0.001 0.004 -Timing stopped at: 0.003 0.001 0.004 +[1] "control$seed is NULL. Replaced by 1" Timing stopped at: 0.004 0 0.004 -[ FAIL 0 | WARN 1 | SKIP 0 | PASS 23 ] +[1] "control$seed is NULL. Replaced by 1" +Timing stopped at: 0.006 0 0.008 +[ FAIL 0 | WARN 2 | SKIP 0 | PASS 23 ] -[ FAIL 0 | WARN 1 | SKIP 0 | PASS 23 ] +[ FAIL 0 | WARN 2 | SKIP 0 | PASS 23 ] > > proc.time() user system elapsed - 2.659 0.107 3.318 + 2.624 0.088 3.383 diff --git a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/tests/testthat/test-runMCMC_btadjust.R b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/tests/testthat/test-runMCMC_btadjust.R index e12b9a73..54fd4b58 100644 --- a/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/tests/testthat/test-runMCMC_btadjust.R +++ b/revdep/checks.noindex/runMCMCbtadjust/old/runMCMCbtadjust.Rcheck/tests/testthat/test-runMCMC_btadjust.R @@ -1,4 +1,4 @@ -context("tunMCMC_btadjust") +context("runMCMC_btadjust") ### minimal setup for running runMCMC_btadjust: see vignette set.seed(1) @@ -135,7 +135,7 @@ testthat::test_that("errors", { inits=Inits,params=params,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000,control=list(convType="Gelman",convtype.alpha=NULL)))) testthat::expect_error((runMCMC_btadjust(data=ModelData,constants=ModelConsts,code=ModelCode,MCMC_language="Nimble", inits=Inits,params=params,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000,control=list(convType="Gelman",convtype.alpha=1.1)))) - + #should give an error because neff.method is not "Stan" or "Coda" testthat::expect_error((runMCMC_btadjust(data=ModelData,constants=ModelConsts,code=ModelCode,MCMC_language="Nimble", @@ -167,6 +167,7 @@ testthat::test_that("errors", { inits=Inits,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000))) + })} @@ -183,7 +184,7 @@ testthat::test_that("errors", { testthat::expect_error((runMCMC_btadjust(data=ModelData.Jags,MCMC_language="Jags", inits=Inits,params=params,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000))) - + #should give an error because code is not of type character with MCMC_language="Jags" testthat::expect_error((runMCMC_btadjust(data=ModelData.Jags,code=1,MCMC_language="Jags", inits=Inits,params=params,neff.min=150,conv.max=1.05,Nchains=2,niter.max=2000))) diff --git a/revdep/library.noindex/greta/new/Rcpp/DESCRIPTION b/revdep/library.noindex/greta/new/Rcpp/DESCRIPTION index afdd5da5..64bc27f5 100644 --- a/revdep/library.noindex/greta/new/Rcpp/DESCRIPTION +++ b/revdep/library.noindex/greta/new/Rcpp/DESCRIPTION @@ -1,10 +1,23 @@ Package: Rcpp Title: Seamless R and C++ Integration -Version: 1.0.12 -Date: 2024-01-08 -Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou, - Nathan Russell, Inaki Ucar, Douglas Bates and John Chambers -Maintainer: Dirk Eddelbuettel +Version: 1.0.13-1 +Date: 2024-11-01 +Authors@R: c(person("Dirk", "Eddelbuettel", role = c("aut", "cre"), email = "edd@debian.org", + comment = c(ORCID = "0000-0001-6419-907X")), + person("Romain", "Francois", role = "aut", + comment = c(ORCID = "0000-0002-2444-4226")), + person("JJ", "Allaire", role = "aut", + comment = c(ORCID = "0000-0003-0174-9868")), + person("Kevin", "Ushey", role = "aut", + comment = c(ORCID = "0000-0003-2880-7407")), + person("Qiang", "Kou", role = "aut", + comment = c(ORCID = "0000-0001-6786-5453")), + person("Nathan", "Russell", role = "aut"), + person("Iñaki", "Ucar", role = "aut", + comment = c(ORCID = "0000-0001-6403-5550")), + person("Doug", "Bates", role = "aut", + comment = c(ORCID = "0000-0001-8316-9503")), + person("John", "Chambers", role = "aut")) Description: The 'Rcpp' package provides R functions as well as C++ classes which offer a seamless integration of R and C++. Many R data types and objects can be mapped back and forth to C++ equivalents which facilitates both writing of new @@ -25,8 +38,18 @@ MailingList: rcpp-devel@lists.r-forge.r-project.org RoxygenNote: 6.1.1 Encoding: UTF-8 NeedsCompilation: yes -Packaged: 2024-01-08 12:50:16 UTC; edd +Packaged: 2024-11-01 13:27:07 UTC; edd +Author: Dirk Eddelbuettel [aut, cre] (), + Romain Francois [aut] (), + JJ Allaire [aut] (), + Kevin Ushey [aut] (), + Qiang Kou [aut] (), + Nathan Russell [aut], + Iñaki Ucar [aut] (), + Doug Bates [aut] (), + John Chambers [aut] +Maintainer: Dirk Eddelbuettel Repository: CRAN -Date/Publication: 2024-01-09 08:20:35 UTC -Built: R 4.3.1; aarch64-apple-darwin20; 2024-01-10 02:58:10 UTC; unix +Date/Publication: 2024-11-02 20:10:02 UTC +Built: R 4.4.1; aarch64-apple-darwin20; 2024-11-02 21:19:22 UTC; unix Archs: Rcpp.so.dSYM diff --git a/revdep/library.noindex/greta/new/Rcpp/Meta/Rd.rds b/revdep/library.noindex/greta/new/Rcpp/Meta/Rd.rds index 6d08e83b..ee9179bd 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/Meta/Rd.rds and b/revdep/library.noindex/greta/new/Rcpp/Meta/Rd.rds differ diff --git a/revdep/library.noindex/greta/new/Rcpp/Meta/features.rds b/revdep/library.noindex/greta/new/Rcpp/Meta/features.rds index bb8956ca..781f60d4 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/Meta/features.rds and b/revdep/library.noindex/greta/new/Rcpp/Meta/features.rds differ diff --git a/revdep/library.noindex/greta/new/Rcpp/Meta/hsearch.rds b/revdep/library.noindex/greta/new/Rcpp/Meta/hsearch.rds index 9a306c90..51161dff 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/Meta/hsearch.rds and b/revdep/library.noindex/greta/new/Rcpp/Meta/hsearch.rds differ diff --git a/revdep/library.noindex/greta/new/Rcpp/Meta/links.rds b/revdep/library.noindex/greta/new/Rcpp/Meta/links.rds index 4c1f4a29..27b93935 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/Meta/links.rds and b/revdep/library.noindex/greta/new/Rcpp/Meta/links.rds differ diff --git a/revdep/library.noindex/greta/new/Rcpp/Meta/nsInfo.rds b/revdep/library.noindex/greta/new/Rcpp/Meta/nsInfo.rds index 074dc932..3d964681 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/Meta/nsInfo.rds and b/revdep/library.noindex/greta/new/Rcpp/Meta/nsInfo.rds differ diff --git a/revdep/library.noindex/greta/new/Rcpp/Meta/package.rds b/revdep/library.noindex/greta/new/Rcpp/Meta/package.rds index db0bd7c5..79053add 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/Meta/package.rds and b/revdep/library.noindex/greta/new/Rcpp/Meta/package.rds differ diff --git a/revdep/library.noindex/greta/new/Rcpp/Meta/vignette.rds b/revdep/library.noindex/greta/new/Rcpp/Meta/vignette.rds index 7f09115e..e46f13ee 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/Meta/vignette.rds and b/revdep/library.noindex/greta/new/Rcpp/Meta/vignette.rds differ diff --git a/revdep/library.noindex/greta/new/Rcpp/NEWS.Rd b/revdep/library.noindex/greta/new/Rcpp/NEWS.Rd index eaaa2ba5..ab37ed69 100644 --- a/revdep/library.noindex/greta/new/Rcpp/NEWS.Rd +++ b/revdep/library.noindex/greta/new/Rcpp/NEWS.Rd @@ -3,6 +3,44 @@ \newcommand{\ghpr}{\href{https://github.com/RcppCore/Rcpp/pull/#1}{##1}} \newcommand{\ghit}{\href{https://github.com/RcppCore/Rcpp/issues/#1}{##1}} +\section{Changes in Rcpp release version 1.0.13-1 (2024-11-01)}{ + \itemize{ + \item Changes in Rcpp API: + \itemize{ + \item Use read-only \code{VECTOR_PTR} and \code{STRING_PTR} only with + with R 4.5.0 or later (Kevin in \ghpr{1342} fixing \ghit{1341}) + } + \item Changes in Rcpp Deployment: + \itemize{ + \item Authors@R is now used in DESCRIPTION as mandated by CRAN + } + } +} + +\section{Changes in Rcpp release version 1.0.13 (2024-07-11)}{ + \itemize{ + \item Changes in Rcpp API: + \itemize{ + \item Set R_NO_REMAP if not already defined (Dirk in \ghpr{1296}) + \item Add variadic templates to be used instead of generated code + (Andrew Johnson in \ghpr{1303}) + \item Count variables were switches to \code{size_t} to avoid warnings + about conversion-narrowing (Dirk in \ghpr{1307}) + \item Rcpp now avoids the usage of the (non-API) DATAPTR function when + accessing the contents of Rcpp Vector objects where possible. (Kevin in + \ghpr{1310}) + \item Rcpp now emits an R warning on out-of-bounds Vector accesses. This + may become an error in a future Rcpp release. (Kevin in \ghpr{1310}) + \item Switch \code{VECTOR_PTR} and \code{STRING_PTR} to new API-compliant + \code{RO} variants (Kevin in \ghpr{1317} fixing \ghit{1316}) + } + \item Changes in Rcpp Deployment: + \itemize{ + \item Small updates to the CI test containers have been made (\ghpr{1304}) + } + } +} + \section{Changes in Rcpp release version 1.0.12 (2024-01-08)}{ \itemize{ \item Changes in Rcpp API: @@ -1795,8 +1833,7 @@ } \item Changes in Rcpp sugar: \itemize{ - \item New function \code{na_omit} based on the StackOverflow thread - \url{http://stackoverflow.com/questions/15953768/} + \item New function \code{na_omit} based on a StackOverflow thread \item New function \code{is_finite} and \code{is_infinite} that reproduces the behavior of R's \code{is.finite} and \code{is.infinite} functions diff --git a/revdep/library.noindex/greta/new/Rcpp/R/Rcpp.rdb b/revdep/library.noindex/greta/new/Rcpp/R/Rcpp.rdb index 446db3bc..511bf0b9 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/R/Rcpp.rdb and b/revdep/library.noindex/greta/new/Rcpp/R/Rcpp.rdb differ diff --git a/revdep/library.noindex/greta/new/Rcpp/R/Rcpp.rdx b/revdep/library.noindex/greta/new/Rcpp/R/Rcpp.rdx index ec4fe9ba..2d3c99f6 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/R/Rcpp.rdx and b/revdep/library.noindex/greta/new/Rcpp/R/Rcpp.rdx differ diff --git a/revdep/library.noindex/greta/new/Rcpp/bib/Rcpp.bib b/revdep/library.noindex/greta/new/Rcpp/bib/Rcpp.bib index 15c21f38..1aac8921 100644 --- a/revdep/library.noindex/greta/new/Rcpp/bib/Rcpp.bib +++ b/revdep/library.noindex/greta/new/Rcpp/bib/Rcpp.bib @@ -136,7 +136,7 @@ @Manual{CRAN:Rcpp Allaire and Kevin Ushey and Qiang Kou and Nathan Russel and John Chambers and Douglas Bates}, year = 2024, - note = {R package version 1.0.12}, + note = {R package version 1.0.13}, url = CRAN # "package=Rcpp" } diff --git a/revdep/library.noindex/greta/new/Rcpp/help/Rcpp.rdb b/revdep/library.noindex/greta/new/Rcpp/help/Rcpp.rdb index f9a1d327..fdd34329 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/help/Rcpp.rdb and b/revdep/library.noindex/greta/new/Rcpp/help/Rcpp.rdb differ diff --git a/revdep/library.noindex/greta/new/Rcpp/help/Rcpp.rdx b/revdep/library.noindex/greta/new/Rcpp/help/Rcpp.rdx index b5079157..9f74e3b8 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/help/Rcpp.rdx and b/revdep/library.noindex/greta/new/Rcpp/help/Rcpp.rdx differ diff --git a/revdep/library.noindex/greta/new/Rcpp/help/aliases.rds b/revdep/library.noindex/greta/new/Rcpp/help/aliases.rds index 98cdf42c..d2aa0719 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/help/aliases.rds and b/revdep/library.noindex/greta/new/Rcpp/help/aliases.rds differ diff --git a/revdep/library.noindex/greta/new/Rcpp/help/paths.rds b/revdep/library.noindex/greta/new/Rcpp/help/paths.rds index 42afdc40..dc0d19a4 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/help/paths.rds and b/revdep/library.noindex/greta/new/Rcpp/help/paths.rds differ diff --git a/revdep/library.noindex/greta/new/Rcpp/html/00Index.html b/revdep/library.noindex/greta/new/Rcpp/html/00Index.html index 6fd611ed..7bf5966c 100644 --- a/revdep/library.noindex/greta/new/Rcpp/html/00Index.html +++ b/revdep/library.noindex/greta/new/Rcpp/html/00Index.html @@ -12,7 +12,7 @@

Seamless R and C++ Integration
[Up] [Top] -

Documentation for package ‘Rcpp’ version 1.0.12

+

Documentation for package ‘Rcpp’ version 1.0.13-1

  • DESCRIPTION file.
  • User guides, package vignettes and other documentation.
  • diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/DataFrame.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/DataFrame.h index b76facf7..0d03efcd 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/DataFrame.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/DataFrame.h @@ -117,8 +117,14 @@ namespace Rcpp{ static DataFrame_Impl create(){ return DataFrame_Impl() ; } - - #include + #if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + static DataFrame_Impl create(const T&... args) { + return DataFrame_Impl::from_list(Parent::create(args...)); + } + #else + #include + #endif private: void set__(SEXP x){ @@ -131,7 +137,7 @@ namespace Rcpp{ } void set_type_after_push(){ - int max_rows = 0; + R_xlen_t max_rows = 0; bool invalid_column_size = false; List::iterator it; // Get the maximum number of rows diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/DottedPair.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/DottedPair.h index e056e2d8..eeb6825a 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/DottedPair.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/DottedPair.h @@ -35,8 +35,14 @@ RCPP_API_CLASS(DottedPair_Impl), DottedPair_Impl(SEXP x) { Storage::set__(x) ; } - - #include + #if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + DottedPair_Impl(const T&... args) { + Storage::set__(pairlist(args...)); + } + #else + #include + #endif void update(SEXP){} diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Function.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Function.h index 298ba5fc..d27bcf2d 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Function.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Function.h @@ -82,7 +82,14 @@ namespace Rcpp{ return Rcpp_fast_eval(call, R_GlobalEnv); } - #include + #if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + SEXP operator()(const T&... args) const { + return invoke(pairlist(args...), R_GlobalEnv); + } + #else + #include + #endif /** * Returns the environment of this function diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/InternalFunction.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/InternalFunction.h index 5a5722be..42f97f90 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/InternalFunction.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/InternalFunction.h @@ -47,9 +47,14 @@ namespace Rcpp{ ) ); } + template + InternalFunction_Impl(RESULT_TYPE (*fun)(T...)) { + set(XPtr >(new CppFunctionN(fun), true)); + } +#else + #include #endif - #include void update(SEXP){} private: diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/InternalFunctionWithStdFunction.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/InternalFunctionWithStdFunction.h index 966da22b..f003b10e 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/InternalFunctionWithStdFunction.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/InternalFunctionWithStdFunction.h @@ -23,13 +23,17 @@ #ifndef Rcpp_InternalFunctionWithStdFunction_h #define Rcpp_InternalFunctionWithStdFunction_h +#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) +#include +#endif #include namespace Rcpp { namespace InternalFunctionWithStdFunction { - + #if !defined(HAS_VARIADIC_TEMPLATES) && !defined(RCPP_USING_CXX11) #include + #endif template class CppFunctionBaseFromStdFunction : public CppFunctionBase { @@ -39,8 +43,7 @@ namespace Rcpp { SEXP operator()(SEXP* args) { BEGIN_RCPP - auto result = call(fun, args); - return Rcpp::module_wrap(result); + return call(fun, args); END_RCPP } @@ -48,22 +51,6 @@ namespace Rcpp { const std::function fun; }; - template - class CppFunctionBaseFromStdFunction : public CppFunctionBase { - public: - CppFunctionBaseFromStdFunction(const std::function &fun) : fun(fun) {} - virtual ~CppFunctionBaseFromStdFunction() {} - - SEXP operator()(SEXP* args) { - BEGIN_RCPP - call(fun, args); - END_RCPP - } - - private: - const std::function fun; - }; - } // namespace InternalFunctionWithStdFunction } // namespace Rcpp diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Language.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Language.h index 03983f5e..a2d250a8 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Language.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Language.h @@ -102,7 +102,19 @@ namespace Rcpp{ * 0.0 is wrapped as a numeric vector using wrap( const& double ) * ... */ - #include + #if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + Language_Impl(const std::string& symbol, const T&... t) { + Storage::set__(pairlist(Rf_install(symbol.c_str()), t...) ); + } + + template + Language_Impl(const Function& function, const T&... t) { + Storage::set__(pairlist(function, t...)); + } + #else + #include + #endif /** * sets the symbol of the call diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Module.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Module.h index 88d3a076..cdb12d4d 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Module.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Module.h @@ -1,5 +1,4 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- -// + // Module.h: Rcpp R/C++ interface class library -- Rcpp modules // // Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois @@ -23,6 +22,7 @@ #define Rcpp_Module_h #include +#include namespace Rcpp{ @@ -85,10 +85,57 @@ namespace Rcpp{ #include #include -#include - // templates CppFunction0, ..., CppFunction65 -#include +#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) +namespace Rcpp { + template + inline void signature(std::string& s, const char* name) { + s.clear(); + s += get_return_type() + " " + name + "("; + int n = sizeof...(T); + int i = 0; + // Using initializer list as c++11 implementation of a fold expression + (void)std::initializer_list{ + (s += get_return_type(), s += (++i == n ? "" : ", "), 0)... }; + s += ")"; + } + + template + class CppFunctionN : public CppFunction { + public: + CppFunctionN(RESULT_TYPE (*fun)(T...), const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun) {} + + SEXP operator()(SEXP* args) { + BEGIN_RCPP + return call(ptr_fun, args); + END_RCPP + } + + inline int nargs() { return sizeof...(T); } + inline void signature(std::string& s, const char* name) { Rcpp::signature(s, name); } + inline DL_FUNC get_function_ptr() { return (DL_FUNC)ptr_fun; } + + private: + RESULT_TYPE (*ptr_fun)(T...); + }; + + template + class CppFunction_WithFormalsN : public CppFunctionN { + public: + CppFunction_WithFormalsN(RESULT_TYPE (*fun)(T...), Rcpp::List formals_, const char* docstring = 0) : + CppFunctionN(fun, docstring), formals(formals_) {} + + SEXP get_formals() { return formals; } + + private: + Rcpp::List formals; + }; +} +#else + #include + // templates CppFunction0, ..., CppFunction65 + #include +#endif #include #include @@ -129,12 +176,86 @@ namespace Rcpp{ private: ParentMethod* parent_method_pointer ; } ; +#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + inline void ctor_signature(std::string& s, const std::string& classname) { + s.assign(classname); + s += "("; + int n = sizeof...(T); + int i = 0; + // Using initializer list as c++11 implementation of a fold expression + (void)std::initializer_list{ + (s += get_return_type(), s += (++i == n ? "" : ", "), 0)... }; + s += ")"; + } + template + class Constructor_Base { + public: + virtual Class* get_new( SEXP* args, int nargs ) = 0 ; + virtual int nargs() = 0 ; + virtual void signature(std::string& s, const std::string& class_name) = 0 ; + } ; + + template + class Constructor: public Constructor_Base { + public: + virtual Class* get_new( SEXP* args, int nargs ){ + return get_new_impl(args, nargs, traits::make_index_sequence()); + } + virtual int nargs(){ return sizeof...(T) ; } + virtual void signature(std::string& s, const std::string& class_name ){ + ctor_signature(s, class_name) ; + } + + private: + template + Class* get_new_impl(SEXP* args, int nargs, traits::index_sequence) { + return new Class( as(args[Is])... ) ; + } + }; + + template + class Factory_Base { + public: + virtual Class* get_new( SEXP* args, int nargs ) = 0 ; + virtual int nargs() = 0 ; + virtual void signature(std::string& s, const std::string& class_name) = 0 ; + } ; + template + class Factory : public Factory_Base { + public: + Factory( Class* (*fun)(T...) ) : ptr_fun(fun){} + virtual Class* get_new( SEXP* args, int nargs ){ + return get_new( args, traits::make_index_sequence() ) ; + } + virtual int nargs(){ return sizeof...(T) ; } + virtual void signature(std::string& s, const std::string& class_name ){ + ctor_signature(s, class_name) ; + } + private: + template + Class* get_new( SEXP* args, traits::index_sequence ){ + return ptr_fun( bare_as(args[I])... ) ; + } + Class* (*ptr_fun)(T...) ; + } ; + + inline bool yes( SEXP* /*args*/, int /* nargs */ ){ + return true ; + } + + template + bool yes_arity( SEXP* /* args */ , int nargs){ + return nargs == n ; + } + +#else #include #include #include - #include +#endif typedef bool (*ValidConstructor)(SEXP*,int) ; typedef bool (*ValidMethod)(SEXP*,int) ; @@ -229,7 +350,7 @@ namespace Rcpp{ typedef std::vector vec_signed_method ; S4_CppOverloadedMethods( vec_signed_method* m, const XP_Class& class_xp, const char* name, std::string& buffer ) : Reference( "C++OverloadedMethods" ){ - int n = m->size() ; + int n = static_cast(m->size()) ; Rcpp::LogicalVector voidness(n), constness(n) ; Rcpp::CharacterVector docstrings(n), signatures(n) ; Rcpp::IntegerVector nargs(n) ; @@ -259,8 +380,70 @@ namespace Rcpp{ } ; -#include -#include +#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + class CppMethodImplN : public CppMethod { + public: + typedef typename std::conditional::type Method; + typedef CppMethod method_class; + typedef typename Rcpp::traits::remove_const_and_reference::type CLEANED_RESULT_TYPE; + + CppMethodImplN(Method m) : method_class(), met(m) {} + SEXP operator()(Class* object, SEXP* args) { + // Can't pass pointer to member function directly to `call()`, so wrap it in a lambda + auto f = [&object, this](T... cpp_args) -> CLEANED_RESULT_TYPE { + return (object->*met)(cpp_args...); + }; + return call(f, args); + } + inline int nargs() { return sizeof...(T); } + inline bool is_void() { return std::is_void::value; } + inline bool is_const() { return IsConst; } + inline void signature(std::string& s, const char* name) { Rcpp::signature(s, name); } + private: + Method met; + }; + + template + using CppMethodN = CppMethodImplN; + + template + using const_CppMethodN = CppMethodImplN; + + template + class Pointer_CppMethodImplN : public CppMethod { + public: + typedef typename std::conditional::type Method; + typedef CppMethod method_class; + typedef typename Rcpp::traits::remove_const_and_reference::type CLEANED_RESULT_TYPE; + + Pointer_CppMethodImplN(Method m) : method_class(), met(m) {} + SEXP operator()(Class* object, SEXP* args) { + // Need to have `object` as the first argument to the function, so wrap it in a lambda + auto f = [&object, this](T... cpp_args) -> CLEANED_RESULT_TYPE { + return met(object, cpp_args...); + }; + return call(f, args); + } + inline int nargs() { return sizeof...(T); } + inline bool is_void() { return std::is_void::value;} + inline bool is_const() { return IsConst; } + inline void signature(std::string& s, const char* name) { Rcpp::signature(s, name); } + private: + Method met; + }; + + template + using Pointer_CppMethodN = Pointer_CppMethodImplN; + + template + using Const_Pointer_CppMethodN = Pointer_CppMethodImplN; +#else + #include + #include +#endif template class CppProperty { @@ -368,8 +551,28 @@ namespace Rcpp{ } ; } -// function factories -#include +#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) +namespace Rcpp { + template + void function(const char* name_, RESULT_TYPE (*fun)(T... t), const char* docstring = 0) { + Rcpp::Module* scope = ::getCurrentScope(); + if (scope) { + scope->Add(name_, new CppFunctionN(fun, docstring)); + } + } + + template + void function(const char* name_, RESULT_TYPE (*fun)(T... t), Rcpp::List formals, const char* docstring = 0) { + Rcpp::Module* scope = ::getCurrentScope(); + if (scope) { + scope->Add(name_, new CppFunction_WithFormalsN(fun, formals, docstring)); + } + } +} +#else + // function factories + #include +#endif namespace Rcpp { @@ -457,4 +660,3 @@ static VARIABLE_IS_NOT_USED SEXP moduleSym = NULL; Rcpp_fast_eval( __load_module_call__, R_GlobalEnv ); #endif - diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Pairlist.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Pairlist.h index 043615ef..d06bf6f3 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Pairlist.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Pairlist.h @@ -42,9 +42,14 @@ namespace Rcpp{ Pairlist_Impl(SEXP x){ Storage::set__(r_cast(x)) ; } - - #include - + #if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + Pairlist_Impl(const T&... args ){ + Storage::set__(pairlist(args... )) ; + } + #else + #include + #endif void update(SEXP x){ SET_TYPEOF( x, LISTSXP ) ; } diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Vector.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Vector.h index e25be1d5..6c95ef8d 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Vector.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/Vector.h @@ -1,5 +1,4 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- -// + // Vector.h: Rcpp R/C++ interface class library -- vectors // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/config.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/config.h index fa75d9dd..5ae0684f 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/config.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/config.h @@ -26,11 +26,11 @@ #define RcppDevVersion(maj, min, rev, dev) (((maj)*1000000) + ((min)*10000) + ((rev)*100) + (dev)) // the currently released version -#define RCPP_VERSION Rcpp_Version(1,0,11) -#define RCPP_VERSION_STRING "1.0.12" +#define RCPP_VERSION Rcpp_Version(1,0,13) +#define RCPP_VERSION_STRING "1.0.13" // the current source snapshot (using four components, if a fifth is used in DESCRIPTION we ignore it) -#define RCPP_DEV_VERSION RcppDevVersion(1,0,12,0) -#define RCPP_DEV_VERSION_STRING "1.0.12.0" +#define RCPP_DEV_VERSION RcppDevVersion(1,0,13,1) +#define RCPP_DEV_VERSION_STRING "1.0.13.1" #endif diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/grow.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/grow.h index e5a36c67..b67d05a6 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/grow.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/grow.h @@ -70,7 +70,18 @@ namespace Rcpp { return grow(Rf_mkString(head), y); } - #include + #if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + SEXP pairlist(const T1& t1) { + return grow( t1, R_NilValue ) ; + } + template + SEXP pairlist(const T& t1, const TArgs&... args) { + return grow(t1, pairlist(args...)); + } + #else + #include + #endif } // namespace Rcpp diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/Proxy_Iterator.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/Proxy_Iterator.h index bc94f112..6ba89176 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/Proxy_Iterator.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/Proxy_Iterator.h @@ -1,6 +1,4 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- -/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ -// + // Proxy_Iterator.h: Rcpp R/C++ interface class library -- // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois @@ -31,7 +29,7 @@ class Proxy_Iterator { public: typedef PROXY& reference ; typedef PROXY* pointer ; - typedef int difference_type ; + typedef R_xlen_t difference_type ; typedef PROXY value_type; typedef std::random_access_iterator_tag iterator_category ; @@ -122,4 +120,3 @@ class Proxy_Iterator { } #endif - diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/SEXP_Iterator.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/SEXP_Iterator.h index 62e604d2..fbb8e2ad 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/SEXP_Iterator.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/SEXP_Iterator.h @@ -37,7 +37,7 @@ class SEXP_Iterator { SEXP_Iterator( ): ptr(){} ; SEXP_Iterator( const SEXP_Iterator& other) : ptr(other.ptr){} ; - SEXP_Iterator( const VECTOR& vec ) : ptr( get_vector_ptr(vec) ){} ; + SEXP_Iterator( const VECTOR& vec ) : ptr( RCPP_VECTOR_PTR(vec) ){} ; SEXP_Iterator& operator=(const SEXP_Iterator& other){ ptr = other.ptr ; return *this ;} diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/export.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/export.h index e433127d..46ce154c 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/export.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/export.h @@ -1,6 +1,4 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- -/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ -// + // export.h: Rcpp R/C++ interface class library -- // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/r_vector.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/r_vector.h index efdf3c8e..589c75fe 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/r_vector.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/internal/r_vector.h @@ -32,6 +32,21 @@ typename Rcpp::traits::storage_type::type* r_vector_start(SEXP x) { return reinterpret_cast(dataptr(x)); } +// add specializations to avoid use of dataptr +#define RCPP_VECTOR_START_IMPL(__RTYPE__, __ACCESSOR__) \ + template <> \ + inline typename Rcpp::traits::storage_type<__RTYPE__>::type* r_vector_start<__RTYPE__>(SEXP x) { \ + return __ACCESSOR__(x); \ + } + +RCPP_VECTOR_START_IMPL(LGLSXP, LOGICAL); +RCPP_VECTOR_START_IMPL(INTSXP, INTEGER); +RCPP_VECTOR_START_IMPL(RAWSXP, RAW); +RCPP_VECTOR_START_IMPL(CPLXSXP, COMPLEX); +RCPP_VECTOR_START_IMPL(REALSXP, REAL); + +#undef RCPP_VECTOR_START_IMPL + /** * The value 0 statically casted to the appropriate type for * the given SEXP type diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/module/class.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/module/class.h index 81562644..d617f164 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/module/class.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/module/class.h @@ -1,5 +1,4 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- -// + // class.h: Rcpp R/C++ interface class library -- Rcpp modules // // Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois @@ -111,8 +110,21 @@ return constructor( docstring, valid ) ; } -#include -#include +#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + self& constructor( const char* docstring = 0, ValidConstructor valid = &yes_arity ){ + AddConstructor( new Constructor , valid, docstring ) ; + return *this ; + } + template + self& factory( Class* (*fun)(T...), const char* docstring = 0, ValidConstructor valid = &yes_arity ){ + AddFactory( new Factory(fun) , valid, docstring ) ; + return *this ; + } +#else + #include + #include +#endif public: @@ -123,8 +135,8 @@ SEXP newInstance( SEXP* args, int nargs ){ BEGIN_RCPP signed_constructor_class* p ; - int n = constructors.size() ; - for( int i=0; ivalid)(args, nargs) ; if( ok ){ @@ -135,7 +147,7 @@ signed_factory_class* pfact ; n = factories.size() ; - for( int i=0; ivalid)(args, nargs) ; if( ok ){ @@ -149,15 +161,15 @@ } bool has_default_constructor(){ - int n = constructors.size() ; + size_t n = constructors.size() ; signed_constructor_class* p ; - for( int i=0; inargs() == 0 ) return true ; } n = factories.size() ; signed_factory_class* pfact ; - for( int i=0; inargs() == 0 ) return true ; } @@ -169,10 +181,10 @@ vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( R_ExternalPtrAddr( method_xp ) ) ; typename vec_signed_method::iterator it = mets->begin() ; - int n = mets->size() ; + size_t n = mets->size() ; method_class* m = 0 ; bool ok = false ; - for( int i=0; ivalid )( args, nargs) ){ m = (*it)->method ; ok = true ; @@ -196,10 +208,10 @@ vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( R_ExternalPtrAddr( method_xp ) ) ; typename vec_signed_method::iterator it = mets->begin() ; - int n = mets->size() ; + size_t n = mets->size() ; method_class* m = 0 ; bool ok = false ; - for( int i=0; ivalid )( args, nargs) ){ m = (*it)->method ; ok = true ; @@ -218,10 +230,10 @@ vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( R_ExternalPtrAddr( method_xp ) ) ; typename vec_signed_method::iterator it = mets->begin() ; - int n = mets->size() ; + size_t n = mets->size() ; method_class* m = 0 ; bool ok = false ; - for( int i=0; ivalid )( args, nargs) ){ m = (*it)->method ; ok = true ; @@ -253,8 +265,47 @@ return *this ; } -#include -#include +#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template + self& method(const char* name_, RESULT_TYPE (Class::*fun)(T...), + const char* docstring = 0, ValidMethod valid = &yes_arity) { + AddMethod( name_, new CppMethodN(fun), valid, docstring); + return *this; + } + template + self& method(const char* name_, RESULT_TYPE (Class::*fun)(T...) const, + const char* docstring = 0, ValidMethod valid = &yes_arity) { + AddMethod( name_, new const_CppMethodN(fun), valid, docstring); + return *this; + } + template + self& nonconst_method(const char* name_, RESULT_TYPE (Class::*fun)(T...), + const char* docstring = 0, ValidMethod valid = &yes_arity) { + AddMethod( name_, new CppMethodN(fun), valid, docstring); + return *this; + } + template + self& const_method(const char* name_, RESULT_TYPE (Class::*fun)(T...) const, + const char* docstring = 0, ValidMethod valid = &yes_arity) { + AddMethod( name_, new const_CppMethodN(fun), valid, docstring); + return *this; + } + template + self& method(const char* name_, RESULT_TYPE (*fun)(Class*, T...), + const char* docstring = 0, ValidMethod valid = &yes_arity) { + AddMethod( name_, new Pointer_CppMethodN(fun), valid, docstring); + return *this; + } + template + self& const_method(const char* name_, RESULT_TYPE (*fun)(const Class*, T...), + const char* docstring = 0, ValidMethod valid = &yes_arity) { + AddMethod( name_, new Const_Pointer_CppMethodN(fun), valid, docstring); + return *this; + } +#else + #include + #include +#endif bool has_method( const std::string& m){ return vec_methods.find(m) != vec_methods.end() ; @@ -274,19 +325,19 @@ } Rcpp::CharacterVector method_names(){ - int n = 0 ; - int s = vec_methods.size() ; + size_t n = 0 ; + size_t s = vec_methods.size() ; typename map_vec_signed_method::iterator it = vec_methods.begin( ) ; - for( int i=0; isecond)->size() ; } Rcpp::CharacterVector out(n) ; it = vec_methods.begin() ; - int k = 0 ; - for( int i=0; isecond)->size() ; std::string name = it->first ; - for( int j=0; jsecond)->size() ; } Rcpp::CharacterVector mnames(n) ; Rcpp::IntegerVector res(n) ; it = vec_methods.begin() ; - int k = 0 ; - for( int i=0; isecond)->size() ; std::string name = it->first ; typename vec_signed_method::iterator m_it = (it->second)->begin() ; - for( int j=0; jnargs() ; } @@ -318,21 +369,21 @@ } Rcpp::LogicalVector methods_voidness(){ - int n = 0 ; - int s = vec_methods.size() ; + size_t n = 0 ; + size_t s = vec_methods.size() ; typename map_vec_signed_method::iterator it = vec_methods.begin( ) ; - for( int i=0; isecond)->size() ; } Rcpp::CharacterVector mnames(n) ; Rcpp::LogicalVector res(n) ; it = vec_methods.begin() ; - int k = 0 ; - for( int i=0; isecond)->size() ; std::string name = it->first ; typename vec_signed_method::iterator m_it = (it->second)->begin() ; - for( int j=0; jis_void() ; } @@ -343,21 +394,21 @@ Rcpp::CharacterVector property_names(){ - int n = properties.size() ; + size_t n = properties.size() ; Rcpp::CharacterVector out(n) ; typename PROPERTY_MAP::iterator it = properties.begin( ) ; - for( int i=0; ifirst ; } return out ; } Rcpp::List property_classes(){ - int n = properties.size() ; + size_t n = properties.size() ; Rcpp::CharacterVector pnames(n) ; Rcpp::List out(n) ; typename PROPERTY_MAP::iterator it = properties.begin( ) ; - for( int i=0; ifirst ; out[i] = it->second->get_class() ; } @@ -366,12 +417,12 @@ } Rcpp::CharacterVector complete(){ - int n = vec_methods.size() - specials ; - int ntotal = n + properties.size() ; + size_t n = vec_methods.size() - specials ; + size_t ntotal = n + properties.size() ; Rcpp::CharacterVector out(ntotal) ; typename map_vec_signed_method::iterator it = vec_methods.begin( ) ; std::string buffer ; - int i=0 ; + size_t i=0 ; for( ; ifirst ; if( buffer[0] == '[' ) continue ; @@ -407,11 +458,11 @@ Rcpp::List fields( const XP_Class& class_xp ){ - int n = properties.size() ; + size_t n = properties.size() ; Rcpp::CharacterVector pnames(n) ; Rcpp::List out(n) ; typename PROPERTY_MAP::iterator it = properties.begin( ) ; - for( int i=0; ifirst ; out[i] = S4_field( it->second, class_xp ) ; } @@ -424,12 +475,12 @@ #if RCPP_DEBUG_LEVEL > 0 Rf_PrintValue( class_xp ) ; #endif - int n = vec_methods.size() ; + size_t n = vec_methods.size() ; Rcpp::CharacterVector mnames(n) ; Rcpp::List res(n) ; typename map_vec_signed_method::iterator it = vec_methods.begin( ) ; vec_signed_method* v; - for( int i=0; ifirst ; v = it->second ; res[i] = S4_CppOverloadedMethods( v , class_xp, it->first.c_str(), buffer ) ; @@ -439,10 +490,10 @@ } Rcpp::List getConstructors( const XP_Class& class_xp, std::string& buffer){ - int n = constructors.size() ; + size_t n = constructors.size() ; Rcpp::List out(n) ; typename vec_signed_constructor::iterator it = constructors.begin( ) ; - for( int i=0; i( *it , class_xp, name, buffer ) ; } return out ; diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/r/headers.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/r/headers.h index 1804f252..c93636c4 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/r/headers.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/r/headers.h @@ -1,7 +1,7 @@ // headers.h: Rcpp R/C++ interface class library -- R headers // // Copyright (C) 2008 - 2009 Dirk Eddelbuettel -// Copyright (C) 2009 - 2022 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2009 - 2024 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -22,8 +22,12 @@ #define RCPP__R__HEADERS__H // include R headers, but set R_NO_REMAP and access everything via Rf_ prefixes -#define MAXELTSIZE 8192 -#define R_NO_REMAP +#ifndef MAXELTSIZE + #define MAXELTSIZE 8192 +#endif +#ifndef R_NO_REMAP + #define R_NO_REMAP +#endif // define strict headers for R to not clash on ERROR, MESSGAGE, etc #ifndef RCPP_NO_STRICT_R_HEADERS diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/traits/named_object.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/traits/named_object.h index 60eec15c..f3734f3d 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/traits/named_object.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/traits/named_object.h @@ -22,6 +22,8 @@ #ifndef Rcpp__traits__named_object__h #define Rcpp__traits__named_object__h +#include + namespace Rcpp{ class Argument ; @@ -63,6 +65,19 @@ template struct is_named : public false_type{}; template struct is_named< named_object > : public true_type {}; template <> struct is_named< Rcpp::Argument > : public true_type {}; + +#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + template struct is_any_named : public false_type {}; + template struct is_any_named : public is_named::type {}; + + template + struct is_any_named + : public std::conditional< + is_any_named::value, + std::true_type, + is_any_named>::type {}; +#endif + } // namespace traits } // namespace Rcpp diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/SubMatrix.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/SubMatrix.h index 98b41729..0bda3ab5 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/SubMatrix.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/SubMatrix.h @@ -1,5 +1,4 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- -// + // SubMatrix.h: Rcpp R/C++ interface class library -- sub matrices // // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois @@ -40,8 +39,8 @@ class SubMatrix : public Rcpp::MatrixBase< RTYPE, true, SubMatrix > { {} inline R_xlen_t size() const { return ((R_xlen_t)ncol()) * nrow() ; } - inline int ncol() const { return nc ; } - inline int nrow() const { return nr ; } + inline R_xlen_t ncol() const { return nc ; } + inline R_xlen_t nrow() const { return nr ; } inline Proxy operator()(int i, int j) const { return iter[ i + j*m_nr ] ; @@ -52,16 +51,16 @@ class SubMatrix : public Rcpp::MatrixBase< RTYPE, true, SubMatrix > { private: MATRIX& m ; vec_iterator iter ; - int m_nr, nc, nr ; + R_xlen_t m_nr, nc, nr ; } ; template class StoragePolicy > -Matrix::Matrix( const SubMatrix& sub ) : VECTOR( Rf_allocMatrix( RTYPE, sub.nrow(), sub.ncol() )), nrows(sub.nrow()) { - int nc = sub.ncol() ; +Matrix::Matrix( const SubMatrix& sub ) : VECTOR( Rf_allocMatrix( RTYPE, (int)sub.nrow(), (int)sub.ncol() )), nrows((int)sub.nrow()) { + R_xlen_t nc = sub.ncol() ; iterator start = VECTOR::begin() ; iterator rhs_it ; - for( int j=0; j void check_indices(IDX* x, R_xlen_t n, R_xlen_t size) { +#ifndef RCPP_NO_BOUNDS_CHECK for (IDX i=0; i < n; ++i) { if (x[i] < 0 or x[i] >= size) { if(std::numeric_limits::is_integer && size > std::numeric_limits::max()) { @@ -144,11 +144,8 @@ class SubsetProxy { stop("index error"); } } +#endif } - #else - template - void check_indices(IDX* x, IDX n, IDX size) {} - #endif void get_indices( traits::identity< traits::int2type > t ) { indices.reserve(rhs_n); @@ -177,10 +174,10 @@ class SubsetProxy { indices.reserve(rhs_n); SEXP names = Rf_getAttrib(lhs, R_NamesSymbol); if (Rf_isNull(names)) stop("names is null"); - SEXP* namesPtr = STRING_PTR(names); - SEXP* rhsPtr = STRING_PTR(rhs); + const SEXP* namesPtr = RCPP_STRING_PTR(names); + const SEXP* rhsPtr = RCPP_STRING_PTR(rhs); for (R_xlen_t i = 0; i < rhs_n; ++i) { - SEXP* match = std::find(namesPtr, namesPtr + lhs_n, *(rhsPtr + i)); + const SEXP* match = std::find(namesPtr, namesPtr + lhs_n, *(rhsPtr + i)); if (match == namesPtr + lhs_n) stop("not found"); indices.push_back(match - namesPtr); diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/Vector.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/Vector.h index 3cac3510..2ce4c18b 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/Vector.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/Vector.h @@ -331,7 +331,7 @@ class Vector : } inline iterator begin() { return cache.get() ; } - inline iterator end() { return cache.get() + size() ; } + inline iterator end() { return cache.get() + static_cast(size()) ; } inline const_iterator begin() const{ return cache.get_const() ; } inline const_iterator end() const{ return cache.get_const() + size() ; } inline const_iterator cbegin() const{ return cache.get_const() ; } @@ -593,7 +593,7 @@ class Vector : return false ; } - int findName(const std::string& name) const { + R_xlen_t findName(const std::string& name) const { SEXP names = RCPP_GET_NAMES(Storage::get__()); if (Rf_isNull(names)) stop("'names' attribute is null"); R_xlen_t n = Rf_xlength(names); @@ -1122,7 +1122,55 @@ class Vector : return Vector( 0 ) ; } - #include + #if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11) + public: + template + static Vector create(const T&... t){ + return create__dispatch( typename traits::integral_constant::value + >::type(), t... ) ; + } + + private: + template + static Vector create__dispatch(traits::false_type, const T&... t){ + Vector res(sizeof...(T)) ; + iterator it(res.begin()); + create_dispatch_impl(it, t...); + return res; + } + template + static Vector create__dispatch( traits::true_type, const T&... t) { + Vector res(sizeof...(T)) ; + Shield names(::Rf_allocVector(STRSXP, sizeof...(T))); + int index = 0; + iterator it(res.begin()); + replace_element_impl(it, names, index, t...); + res.attr("names") = names; + return res; + } + template + static void create_dispatch_impl(iterator& it, const T& t) { + *it = converter_type::get(t); + } + + template + static void create_dispatch_impl(iterator& it, const T& t, const TArgs&... args) { + *it = converter_type::get(t); + create_dispatch_impl(++it, args...); + } + template + static void replace_element_impl(iterator& it, Shield& names, int& index, const T& t) { + replace_element(it, names, index, t); + } + template + static void replace_element_impl(iterator& it, Shield& names, int& index, const T& t, const TArgs&... args) { + replace_element(it, names, index, t); + replace_element_impl(++it, names, ++index, args...); + } + #else + #include + #endif public: diff --git a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/traits.h b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/traits.h index 1e01d93d..c6d76d69 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/traits.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/Rcpp/vector/traits.h @@ -35,22 +35,36 @@ namespace traits{ typedef typename r_vector_const_proxy::type const_proxy ; typedef typename storage_type::type storage_type ; - r_vector_cache() : start(0){} ; + r_vector_cache() : start(0), size(0) {} ; + inline void update( const VECTOR& v ) { - start = ::Rcpp::internal::r_vector_start(v) ; + start = ::Rcpp::internal::r_vector_start(v) ; + size = v.size(); } + inline iterator get() const { return start; } inline const_iterator get_const() const { return start; } - inline proxy ref() { return *start ;} - inline proxy ref(R_xlen_t i) { return start[i] ; } + inline proxy ref() { check_index(0); return start[0] ;} + inline proxy ref(R_xlen_t i) { check_index(i); return start[i] ; } + + inline proxy ref() const { check_index(0); return start[0] ;} + inline proxy ref(R_xlen_t i) const { check_index(i); return start[i] ; } - inline proxy ref() const { return *start ;} - inline proxy ref(R_xlen_t i) const { return start[i] ; } + private: - private: - iterator start ; + void check_index(R_xlen_t i) const { +#ifndef RCPP_NO_BOUNDS_CHECK + if (i >= size) { + warning("subscript out of bounds (index %s >= vector size %s)", i, size); + } +#endif + } + + iterator start ; + R_xlen_t size ; } ; + template class StoragePolicy = PreserveStorage> class proxy_cache{ public: @@ -66,17 +80,24 @@ namespace traits{ p = const_cast(&v) ; } inline iterator get() const { return iterator( proxy(*p, 0 ) ) ;} - // inline const_iterator get_const() const { return const_iterator( *p ) ;} inline const_iterator get_const() const { return const_iterator( const_proxy(*p, 0) ) ; } - inline proxy ref() { return proxy(*p,0) ; } - inline proxy ref(R_xlen_t i) { return proxy(*p,i);} + inline proxy ref() { check_index(0); return proxy(*p,0) ; } + inline proxy ref(R_xlen_t i) { check_index(i); return proxy(*p,i);} - inline const_proxy ref() const { return const_proxy(*p,0) ; } - inline const_proxy ref(R_xlen_t i) const { return const_proxy(*p,i);} + inline const_proxy ref() const { check_index(0); return const_proxy(*p,0) ; } + inline const_proxy ref(R_xlen_t i) const { check_index(i); return const_proxy(*p,i);} private: VECTOR* p ; + + void check_index(R_xlen_t i) const { +#ifndef RCPP_NO_BOUNDS_CHECK + if (i >= p->size()) { + warning("subscript out of bounds (index %s >= vector size %s)", i, p->size()); + } +#endif + } } ; // regular types for INTSXP, REALSXP, ... diff --git a/revdep/library.noindex/greta/new/Rcpp/include/RcppCommon.h b/revdep/library.noindex/greta/new/Rcpp/include/RcppCommon.h index a2760ec7..5cbe895b 100644 --- a/revdep/library.noindex/greta/new/Rcpp/include/RcppCommon.h +++ b/revdep/library.noindex/greta/new/Rcpp/include/RcppCommon.h @@ -28,6 +28,7 @@ // #define RCPP_DEBUG_MODULE_LEVEL 1 #include +#include /** * \brief Rcpp API diff --git a/revdep/library.noindex/greta/new/Rcpp/libs/Rcpp.so b/revdep/library.noindex/greta/new/Rcpp/libs/Rcpp.so index fe77c63f..3c435cd1 100755 Binary files a/revdep/library.noindex/greta/new/Rcpp/libs/Rcpp.so and b/revdep/library.noindex/greta/new/Rcpp/libs/Rcpp.so differ diff --git a/revdep/library.noindex/greta/new/Rcpp/libs/Rcpp.so.dSYM/Contents/Resources/DWARF/Rcpp.so b/revdep/library.noindex/greta/new/Rcpp/libs/Rcpp.so.dSYM/Contents/Resources/DWARF/Rcpp.so index b353d8d9..4fc858b9 100644 Binary files a/revdep/library.noindex/greta/new/Rcpp/libs/Rcpp.so.dSYM/Contents/Resources/DWARF/Rcpp.so and b/revdep/library.noindex/greta/new/Rcpp/libs/Rcpp.so.dSYM/Contents/Resources/DWARF/Rcpp.so differ diff --git a/revdep/library.noindex/greta/new/Rcpp/tinytest/cpp/InternalFunction.cpp b/revdep/library.noindex/greta/new/Rcpp/tinytest/cpp/InternalFunction.cpp index c6d2515e..7261da9c 100644 --- a/revdep/library.noindex/greta/new/Rcpp/tinytest/cpp/InternalFunction.cpp +++ b/revdep/library.noindex/greta/new/Rcpp/tinytest/cpp/InternalFunction.cpp @@ -27,6 +27,15 @@ int add(int a, int b) { return a + b; } +void dummy(int a, int b) { + Rcpp::Rcout << "dummy called" << std::endl; +} + +// [[Rcpp::export]] +Rcpp::InternalFunction getDummy() { + return Rcpp::InternalFunction( &dummy ); +} + // [[Rcpp::export]] Rcpp::InternalFunction getAdd() { diff --git a/revdep/library.noindex/greta/new/Rcpp/tinytest/cpp/Vector.cpp b/revdep/library.noindex/greta/new/Rcpp/tinytest/cpp/Vector.cpp index 49579695..4fc26b7e 100644 --- a/revdep/library.noindex/greta/new/Rcpp/tinytest/cpp/Vector.cpp +++ b/revdep/library.noindex/greta/new/Rcpp/tinytest/cpp/Vector.cpp @@ -886,3 +886,13 @@ bool CharacterVector_test_equality_crosspolicy(CharacterVector x, Vector // for NULL #include -/* FIXME: +/* FIXME: Check these declarations against the C/Fortran source code. */ /* .Call calls */ -extern SEXP rcpp_hello_world_cpp(); -extern SEXP _rcpp_module_boot_NumEx(); -extern SEXP _rcpp_module_boot_RcppClassModule(); -extern SEXP _rcpp_module_boot_stdVector(); +extern SEXP rcpp_hello_world_cpp(void); +extern SEXP _rcpp_module_boot_NumEx(void); +extern SEXP _rcpp_module_boot_RcppClassModule(void); +extern SEXP _rcpp_module_boot_stdVector(void); static const R_CallMethodDef CallEntries[] = { {"rcpp_hello_world_cpp", (DL_FUNC) &rcpp_hello_world_cpp, 0}, diff --git a/revdep/library.noindex/greta/new/Rcpp/tinytest/test_packageversion.R b/revdep/library.noindex/greta/new/Rcpp/tinytest/test_packageversion.R index 6df612c7..871510d5 100644 --- a/revdep/library.noindex/greta/new/Rcpp/tinytest/test_packageversion.R +++ b/revdep/library.noindex/greta/new/Rcpp/tinytest/test_packageversion.R @@ -1,5 +1,5 @@ -## Copyright (C) 2019 - 2022 Dirk Eddelbuettel +## Copyright (C) 2019 - 2024 Dirk Eddelbuettel ## ## This file is part of Rcpp. ## @@ -30,7 +30,7 @@ v <- as.integer(unlist(strsplit(pvstr, "\\."))) relstr <- as.character(as.package_version(paste(v[1:3], collapse="."))) ## call C++ function returning list of six values, three each for 'release' and 'dev' version -res <- checkVersion(v) +res <- checkVersion(v[1:min(4, length(v))]) ## basic check: is the #defined version equal to the computed version (issue #1014) diff --git a/revdep/library.noindex/greta/new/Rcpp/tinytest/test_rcpp_package_skeleton.R b/revdep/library.noindex/greta/new/Rcpp/tinytest/test_rcpp_package_skeleton.R index 23ec2fbd..b1107c31 100644 --- a/revdep/library.noindex/greta/new/Rcpp/tinytest/test_rcpp_package_skeleton.R +++ b/revdep/library.noindex/greta/new/Rcpp/tinytest/test_rcpp_package_skeleton.R @@ -69,7 +69,7 @@ for (file in grep("RcppExports.R", R_files, invert=TRUE, value=TRUE)) { code <- readLines(file) fn <- eval(parse(text=paste(code, collapse="\n"))) fn_name <- gsub(".*/(.*)\\.R$", "\\1", file) - checkIdentical(fn, get(fn_name), + checkIdentical(fn, base::get(fn_name), sprintf("we parsed the function '%s' correctly", fn_name) ) } diff --git a/revdep/library.noindex/greta/new/Rcpp/tinytest/test_vector.R b/revdep/library.noindex/greta/new/Rcpp/tinytest/test_vector.R index 4be170ea..e8138e24 100644 --- a/revdep/library.noindex/greta/new/Rcpp/tinytest/test_vector.R +++ b/revdep/library.noindex/greta/new/Rcpp/tinytest/test_vector.R @@ -694,3 +694,11 @@ expect_equal(data, data2) # test.CharacterVector_test_equality <- function(){ expect_true( !CharacterVector_test_equality("foo", "bar") ) expect_true( !CharacterVector_test_equality_crosspolicy("foo", "bar") ) + +# https://github.com/RcppCore/Rcpp/issues/1308 +# tests disabled since these could trigger UBSAN warnings / crashes +#expect_warning(NumericVector_test_out_of_bounds_read(numeric(0), 0)) +#expect_warning(NumericVector_test_out_of_bounds_read(numeric(1), 1)) +#expect_warning(CharacterVector_test_out_of_bounds_read(character(0), 0)) +#expect_warning(CharacterVector_test_out_of_bounds_read(character(1), 1)) + diff --git a/revdep/library.noindex/greta/new/future/DESCRIPTION b/revdep/library.noindex/greta/new/future/DESCRIPTION index 61a50db5..96ef1602 100644 --- a/revdep/library.noindex/greta/new/future/DESCRIPTION +++ b/revdep/library.noindex/greta/new/future/DESCRIPTION @@ -1,8 +1,8 @@ Package: future -Version: 1.33.1 +Version: 1.34.0 Title: Unified Parallel and Distributed Processing in R for Everyone Imports: digest, globals (>= 0.16.1), listenv (>= 0.8.0), parallel, - parallelly (>= 1.34.0), utils + parallelly (>= 1.38.0), utils Suggests: methods, RhpcBLASctl, R.rsp, markdown VignetteBuilder: R.rsp Authors@R: c(person("Henrik", "Bengtsson", @@ -31,12 +31,13 @@ ByteCompile: TRUE URL: https://future.futureverse.org, https://github.com/HenrikBengtsson/future BugReports: https://github.com/HenrikBengtsson/future/issues -RoxygenNote: 7.2.3 +Encoding: UTF-8 +RoxygenNote: 7.3.2 NeedsCompilation: no -Packaged: 2023-12-21 22:22:38 UTC; henrik +Packaged: 2024-07-29 15:02:12 UTC; henrik Author: Henrik Bengtsson [aut, cre, cph] () Maintainer: Henrik Bengtsson Repository: CRAN -Date/Publication: 2023-12-22 07:20:02 UTC -Built: R 4.3.1; ; 2023-12-22 08:38:00 UTC; unix +Date/Publication: 2024-07-29 16:50:05 UTC +Built: R 4.4.0; ; 2024-07-29 20:11:31 UTC; unix diff --git a/revdep/library.noindex/greta/new/future/Meta/Rd.rds b/revdep/library.noindex/greta/new/future/Meta/Rd.rds index 0a3e5220..a8cac368 100644 Binary files a/revdep/library.noindex/greta/new/future/Meta/Rd.rds and b/revdep/library.noindex/greta/new/future/Meta/Rd.rds differ diff --git a/revdep/library.noindex/greta/new/future/Meta/demo.rds b/revdep/library.noindex/greta/new/future/Meta/demo.rds index 1f47e934..0968232e 100644 Binary files a/revdep/library.noindex/greta/new/future/Meta/demo.rds and b/revdep/library.noindex/greta/new/future/Meta/demo.rds differ diff --git a/revdep/library.noindex/greta/new/future/Meta/features.rds b/revdep/library.noindex/greta/new/future/Meta/features.rds index bb8956ca..ded31532 100644 Binary files a/revdep/library.noindex/greta/new/future/Meta/features.rds and b/revdep/library.noindex/greta/new/future/Meta/features.rds differ diff --git a/revdep/library.noindex/greta/new/future/Meta/hsearch.rds b/revdep/library.noindex/greta/new/future/Meta/hsearch.rds index eac6c9d5..6b127c11 100644 Binary files a/revdep/library.noindex/greta/new/future/Meta/hsearch.rds and b/revdep/library.noindex/greta/new/future/Meta/hsearch.rds differ diff --git a/revdep/library.noindex/greta/new/future/Meta/links.rds b/revdep/library.noindex/greta/new/future/Meta/links.rds index 5b39f751..eac51cb9 100644 Binary files a/revdep/library.noindex/greta/new/future/Meta/links.rds and b/revdep/library.noindex/greta/new/future/Meta/links.rds differ diff --git a/revdep/library.noindex/greta/new/future/Meta/nsInfo.rds b/revdep/library.noindex/greta/new/future/Meta/nsInfo.rds index 3379194f..43a87832 100644 Binary files a/revdep/library.noindex/greta/new/future/Meta/nsInfo.rds and b/revdep/library.noindex/greta/new/future/Meta/nsInfo.rds differ diff --git a/revdep/library.noindex/greta/new/future/Meta/package.rds b/revdep/library.noindex/greta/new/future/Meta/package.rds index 561a7c8d..0563d919 100644 Binary files a/revdep/library.noindex/greta/new/future/Meta/package.rds and b/revdep/library.noindex/greta/new/future/Meta/package.rds differ diff --git a/revdep/library.noindex/greta/new/future/Meta/vignette.rds b/revdep/library.noindex/greta/new/future/Meta/vignette.rds index 4e2a2745..fd964321 100644 Binary files a/revdep/library.noindex/greta/new/future/Meta/vignette.rds and b/revdep/library.noindex/greta/new/future/Meta/vignette.rds differ diff --git a/revdep/library.noindex/greta/new/future/NAMESPACE b/revdep/library.noindex/greta/new/future/NAMESPACE index e23fbb79..ac88a601 100644 --- a/revdep/library.noindex/greta/new/future/NAMESPACE +++ b/revdep/library.noindex/greta/new/future/NAMESPACE @@ -17,6 +17,7 @@ S3method(getExpression,Future) S3method(getExpression,MulticoreFuture) S3method(getExpression,MultisessionFuture) S3method(getExpression,UniprocessFuture) +S3method(globals,Future) S3method(journal,Future) S3method(journal,FutureJournal) S3method(journal,FutureJournalCondition) @@ -35,6 +36,7 @@ S3method(nbrOfWorkers,cluster) S3method(nbrOfWorkers,future) S3method(nbrOfWorkers,multiprocess) S3method(nbrOfWorkers,uniprocess) +S3method(packages,Future) S3method(plot,Mandelbrot) S3method(print,Future) S3method(print,FutureCondition) @@ -178,6 +180,7 @@ importFrom(parallelly,isNodeAlive) importFrom(parallelly,makeClusterMPI) importFrom(parallelly,makeClusterPSOCK) importFrom(parallelly,makeNodePSOCK) +importFrom(parallelly,serializedSize) importFrom(parallelly,supportsMulticore) importFrom(utils,capture.output) importFrom(utils,file_test) diff --git a/revdep/library.noindex/greta/new/future/NEWS.md b/revdep/library.noindex/greta/new/future/NEWS.md index 137e4653..98c8ba8e 100644 --- a/revdep/library.noindex/greta/new/future/NEWS.md +++ b/revdep/library.noindex/greta/new/future/NEWS.md @@ -1,3 +1,46 @@ +# Version 1.34.0 [2024-07-29] + +## New Features + + * Added support for backend maintainers to specify "cleanup" hook + functions on future strategies, which are called when switching + future plan. These hook functions are specified via the optional + `cleanup` attribute, cf. `attr(cluster, "cleanup")`. + +## Performance + + * Size calculation of globals is now done using the much faster + `parallelly::serializedSize()`. + +## Bug Fixes + + * `resolved()` for `ClusterFuture`:s would produce `Error: + 'inherits(future, "Future")' is not TRUE` instead of an intended, + informative error message that the connection to the parallel + worker is broken. + + +# Version 1.33.2 [2024-03-23] + +## Performance + + * Decreased the overhead of launching futures that occurred for future + strategies that used a complex `workers` argument. For example, + `plan(cluster, workers = cl)`, where `cl` is a `cluster` object, + would come with an extra overhead, because the `workers` object was + unnecessarily transferred to the cluster nodes. + +## Miscellaneous + + * Now `plan(multisession, workers = I(n))`, and same for `cluster`, + preserves the "AsIs" class attribute on the `workers` argument so + that it is propagated to `parallelly::makeClusterWorkers()`. + +## Documentation + + * Clarify that packages must not change any of the `future.*` options. + + # Version 1.33.1 [2023-12-21] ## Bug Fixes @@ -6,7 +49,7 @@ circumstances call `local()` on the global search path rather than `base::local()` as intended. For example, if a package that exports its own `local()` function was attached, then that would be - called instead, often leading to a hard to troubleshoot error. + called instead, often leading to a hard-to-troubleshoot error. # Version 1.33.0 [2023-07-01] diff --git a/revdep/library.noindex/greta/new/future/R/future.rdb b/revdep/library.noindex/greta/new/future/R/future.rdb index 2cf8fb33..11ad4713 100644 Binary files a/revdep/library.noindex/greta/new/future/R/future.rdb and b/revdep/library.noindex/greta/new/future/R/future.rdb differ diff --git a/revdep/library.noindex/greta/new/future/R/future.rdx b/revdep/library.noindex/greta/new/future/R/future.rdx index e454f451..0ca18572 100644 Binary files a/revdep/library.noindex/greta/new/future/R/future.rdx and b/revdep/library.noindex/greta/new/future/R/future.rdx differ diff --git a/revdep/library.noindex/greta/new/future/WORDLIST b/revdep/library.noindex/greta/new/future/WORDLIST index 8caa3efb..51559aeb 100644 --- a/revdep/library.noindex/greta/new/future/WORDLIST +++ b/revdep/library.noindex/greta/new/future/WORDLIST @@ -1,492 +1,496 @@ +ALTREP +AVAILABLECORES AppVeyor AsIs +BAM BatchJobs -batchtools -callr -ClusterFuture +Bengtsson +CFunc CMD CMRG -configurating -cut'n'pasteable +ClusterFuture +CppMethod +Ctrl +DBIConnection +DJOB +DLLHandle +DMatrix DNS -ethz -finalizer +DT +FASTQ FQDN -frontend +FastqFile +FastqStreamer +FastqStreamerList FutureCondition FutureError +FutureEvaluationCondition +FutureEvaluationError +FutureEvaluationWarning +FutureEvaulationMessage FutureGlobals FutureMessage +FutureRegistry FutureResult FutureStrategy +FutureStrategyList +Futureverse FutureWarning -globals Globals -hostname -hostnames -hpc +HB HPC -ing +HenrikBengtsson +IPv +Ik +ImageMagick +Keras +KiB L'Ecuyer +L'Ecuyer's +LSB +LSF LaBar LibreSSL -listenv -LSF -macOS -maechler +MAXSIZE +MPIcluster +MSYS +MULTITHREADING Maechler -mc MiB MinGW -mpi -MSYS -multiprocess +MulticoreFuture Multiprocess -multisession Multisession MultisessionFuture -nitty +MyMachine +MyParallelFuture +NCPUS +NMF +NOTEs NSE +NSLOTS +NUM +NUMPROC +NativeSymbol +NetCDF +NumericVector +ONREFERENCE OpenLava +OpenMP OpenSSH -parallelization -Parallelization -pid +OutDec +PBSPro PID -pids PIDs +POSIXct PPK -pre -Pre +PPN PSOCK +Parallelization +Pre PuTTY +Qu +RPolarsDataFrame +RSP +RSQLite +RStudio +RasterLayer +Rcpp +RcppParallel +RegisteredNativeSymbol +RhpcBLASctl +RichSOCKcluster +RichSOCKnode Rmpi +RngFutureCondition +RngFutureError +RngFutureWarning +Rprofile +Rscript +Rscriptbd Rslaves -RStudio -se -SequentialFuture -setTimeLimit +Rtmpi +RtmpxNyIyK +SEXP SGE -sig +SIGINT +SOCKcluster +SOCKnode +SQLiteConnection +SUPPORTSMULTICORE +SequentialFuture +ShortRead Slurm -subprocesses -tasklist +SolexaPath +SpatRaster +SpatVector +Sys Topologies -uniprocess +UDPipe +UnexpectedFutureResultError +UniprocessFuture +UseMethod +VM +VignetteAuthor +VignetteEngine +VignetteIndexEntry +VignetteKeyword +VignetteTangle +Wishlist XDR +XMLInternalDocument +XMLInternalElementNode +XMLInternalNode abc +adam +adaptor +addNamespace +aeeba af +agaricus alice alist alnum -ALTREP +analysisPath +anonymize +anonymized +appveyor args async +attr autoStop +autoStopCluster availableCores -AVAILABLECORES availableMulticore availableWorkers +bace backtrace +bams +baseenv +batchtools bc +bfr +bigmemory +bioconductor +calc +callr +captureOutput +cb +ccd +cdd +ce +cfunction +chr +ci +cleanEx closeAllConnections +conditionMessage +configurating +conn connectTimeout +covr +cpp cpus -Ctrl +cran +csv +customWorkers +cut'n'pasteable +dbConnect +ddb +deprecations +detectCores df -DJOB +dfn +difftime +dir +doFuture +doMC +doSEQ +dontshow +dopar +dr +dtrain +dv +eadc +enclos env envir envs +ethz +eval +exDIF +exampleData expr +extdata externalptr +fastq +fb +fcn +fftempdir +fileext +finalizer findGlobals +foreach +fq +fqs +frink +frontend +fs furrr futureAssign futureCall -FutureEvaluationCondition -FutureEvaluationError -FutureEvaluationWarning -FutureEvaulationMessage futureOf -FutureStrategyList +futureSessionInfo +futurized gc +getExpression getGlobalsAndPackages +getNodeSet getOption +getcwd +getpid +ging +github +glmnet +globalenv +globals +globalsOf +grd +gsub +gz +haha halfCores hardcoded +hexcode +hostname +hostnames +hpc +hpp +htseq +https +igraph +ik +imagemagick immediateCondition -IPv -kk -L'Ecuyer's -lapply -libPaths -libs -linux -LSB -makeCluster -makeClusterMPI -makeClusterPSOCK +immediatedly +ing +inq +interpretable +interweaved +io +ipc +iter +jclassName +jeroen +jinit +jj +keepme +keras +kk +lang +lapply +libPaths +libs +linux +listenv +loadNamespace +lp +lpdf +macOS +maechler +magick +magrittr +makeCluster +makeClusterMPI +makeClusterPSOCK makeNodePSOCK makePSOCKcluster mandelbrot maxCores maxSize -MAXSIZE +mc mclapply +md +mdebug +mee memoization +mget +mhost mingw -MPIcluster -MulticoreFuture +mortem +mpi +mpid +multiprocess +multisession multithreading -MULTITHREADING myExternalIP myInternalIP myip +myparallel +mypkg +nam +nbrOfFreeWorkers nbrOfWorkers -NCPUS +nc +ncdf +ncid +ncol +ncores +ncvar +nd +ndims +netCDF +nitty nnn -NSLOTS +nodename +nodeset +nopath +notvoid +nrow ntasks -NUM -NUMPROC +num +ny objectSize onError onMissing onMisuse onReference -ONREFERENCE oo +oopts oplan -OutDec -PBSPro +os +packageVersion +parSapply +parallelization +parallelize +parallelly pc +performant +pid +pids plink -PPN +plyr +png +polars +pre +pred +prepending +preprocess +ptr purrr +pwd +py +rJava +rast +rds +readLines +readRDS +registerDoFuture +reis +relu renice reproducibility resignal resignaled -RhpcBLASctl -RichSOCKcluster -RichSOCKnode +reticulate +revdepcheck +rhub rng rnorm +roundtrip +rpolars rscript -Rscript rshcmd rshlogfile +rsp +rstan rstudio -Rtmpi runif +sQuote +sapply +saveRDS +sc +se sessionDetails -SEXP -SIGINT +setTimeLimit +setalloccol +setosa +setwd +shp +sig simpleError +simplicitly slaveRSOCK slurm -SOCKcluster -sQuote +sockconn +socketOptions +softmax +sourceCpp +sp +sparklyr +splitted +ss +stan +stanfit +stanmodel +stderr stdout stopCluster +stopifnot +str subassignments +subclasses suboptimal +subprocesses supportsMulticore -SUPPORTSMULTICORE -tmp -traceback -UnexpectedFutureResultError -UniprocessFuture -useFancyQuotes -UseMethod -warnPartialMatchDollar -workRSOCK -yYF - -Bengtsson -bfr -captureOutput -cran -detectCores -getpid -github -globalsOf -gsub -HB -HenrikBengtsson -https -md -rsp -RSP -stopifnot -str -Sys -topologies -tryCatch -VignetteAuthor -VignetteEngine -VignetteIndexEntry -VignetteKeyword -VignetteTangle -withCapture - -doFuture -dopar -fb -foreach -interweaved -nd -num -Qu -registerDoFuture -setosa -simplicitly -stderr suppressMessages -versicolor -virginica -Wishlist - -BAM -bams -chr -customWorkers -dir -fastq -FASTQ -fq -fqs -htseq -jj -keepme -mhost -mpid -nodename -ss -thost -tpid -unlist - -bace -baseenv -cb -ccd -cdd -ce -ddb -DT -enclos -eval -haha -igraph -mget -MyMachine -NOTEs -ny -png -sapply -yoo - - -attr -conn -csv -dbConnect -DBIConnection -exDIF -frink -futurized -getcwd -getExpression -ging -ik -Ik -ImageMagick -immediatedly -inq -io -jclassName -jeroen -jinit -keras -Keras -lang -magick -mee -mortem -myparallel -MyParallelFuture -nam -NativeSymbol -nc -ncdf -ncid -ncores -ncvar -ndims -netCDF -NetCDF -NumericVector -os -parallelize -prepending -pwd -py -Rcpp -readLines -reis -relu -reticulate -rJava -Rprofile -RSQLite -rstan -sc -SOCKnode -softmax -sourceCpp -sparklyr -SQLiteConnection -stanmodel -subclasses +tagnames +tasklist tbl +tempdir +tempfile +terra +tf +thost +tif +tmp tokenise tokenizer +topologies +tpid +traceback +travis +tryCatch +tsv udmodel udp udpipe -UDPipe +unhandled +uniprocess +unlist +unmarshal unserialize +useFancyQuotes +useXDR varid varndims -VM +vect +versicolor +virginica +warnPartialMatchDollar wb -deprecations -autoStopCluster -parallelly -setwd -tempdir -useXDR -cleanEx -dontshow -fcn -gz -mypkg -preprocess -sockconn -tsv -adaptor -appveyor -ci -dfn -doMC -doSEQ -glmnet -NMF -plyr -revdepcheck -travis -www -agaricus -covr -DMatrix -dtrain -eadc -fileext -grd -interpretable -mdebug -nbrOfFreeWorkers -packageVersion -RasterLayer -rds -RngFutureCondition -RngFutureError -RngFutureWarning -RtmpxNyIyK -tempfile -tf +withCapture +workRSOCK writeStart www +www xgb xgboost -parSapply -roundtrip -analysisPath -bioconductor -CppMethod -dr -dv -extdata -FastqFile -FastqStreamer -FastqStreamerList -fs -KiB -notvoid -nrow -ptr -rast -RegisteredNativeSymbol -ShortRead -shp -SolexaPath -sp -SpatRaster -SpatVector -terra -tif -vect -OpenMP -RcppParallel -nodeset -futureSessionInfo -CFunc -cfunction -DLLHandle -FutureRegistry -imagemagick -iter -lp -lpdf -socketOptions -stan -stanfit -calc -conditionMessage -difftime -POSIXct -setalloccol -loadNamespace -unhandled -anonymize -anonymized -fftempdir -nopath -splitted -aeeba -unmarshal -magrittr -cpp -globalenv -hexcode -hpp -Rscriptbd -addNamespace -exampleData -getNodeSet -readRDS -saveRDS -tagnames xmlAttrs xmlDeserializeHook xmlGetAttr -XMLInternalElementNode -XMLInternalDocument -XMLInternalNode xmlParse xmlSerializeHook xyz -adam -pred +yYF +yoo diff --git a/revdep/library.noindex/greta/new/future/doc/future-3-topologies.html b/revdep/library.noindex/greta/new/future/doc/future-3-topologies.html index 09795617..438263b3 100644 --- a/revdep/library.noindex/greta/new/future/doc/future-3-topologies.html +++ b/revdep/library.noindex/greta/new/future/doc/future-3-topologies.html @@ -207,12 +207,12 @@

    Built-in protection a

    Although this does not give an error, we will find that the inner layer of futures will be processed sequentially just as if we would use plan(list(multisession, sequential)). This behavior is due to the built-in protection against nested parallelism. If both layers would run in parallel, each using the 8 cores available on the machine, we would be running 8 * 8 = 64 parallel processes - that would for sure overload our computer. What happens internally is that for the outer layer, availableCores() equals eight (8), whereas for the inner layer it equals one (1).

    Now, we could imagine that we process the outer layer with, say, two parallel futures, and then the inner layer with four parallel futures. In that case, we would end up running on at most eight cores (= 2 * 4). This can be achieved by forcing a fixed number of workers at each layer:

    -
    plan(list(tweak(multisession, workers = 2), tweak(multisession, workers = 4)))
    +
    plan(list(tweak(multisession, workers = 2), tweak(multisession, workers = I(4))))
     
    -

    When using this approach, there is a risk of setting up too many concurrent workers. To make sure the setup respects availableCores(), use something like:

    +

    When using this approach, there is a risk of setting up too many concurrent workers. Because Futureverse has a built-in protection, we need to declare nested workers using the As-Is I(.) function, which basically tells the parallel framework “trust us, we know what we are doing”. To minimize the risk of mistakes and to make sure our setup respects availableCores(), use something like:

    plan(list(
       tweak(multisession, workers = availableCores() %/% 4),
    -  tweak(multisession, workers = 4)
    +  tweak(multisession, workers = I(4))
     ))
     

    However, before using nested parallelization on a single machine, make sure it is actually more efficient than using parallelization in only one of the layers.

    @@ -226,7 +226,7 @@

    An ad-hoc compute cluster

    nodes <- rep(c("n1", "n2", "n3"), each = 8)
     plan(list(
       tweak(cluster, workers = nodes),
    -  tweak(multisession, workers = 2)
    +  tweak(multisession, workers = I(2))
     ))
     

    This will cause up to 24 (= 3*8) samples to be processed in parallel each processing two chromosomes at the same time.

    @@ -304,7 +304,7 @@

    Example: Adj
    halfCores <- function() { max(1, round(0.5 * availableCores()))
     plan(list(
       tweak(cluster, workers = nodes),
    -  tweak(multisession, workers = halfCores)
    +  tweak(multisession, workers = I(halfCores))
     ))
     

    With this, each node will use at most 50% of the cores available. @@ -321,7 +321,7 @@

    Example: Adj } plan(list( tweak(cluster, workers = nodes), - tweak(multisession, workers = customWorkers) + tweak(multisession, workers = I(customWorkers)) ))

    In this case, node n1 will always use two cores, n2 three cores, diff --git a/revdep/library.noindex/greta/new/future/doc/future-3-topologies.md.rsp b/revdep/library.noindex/greta/new/future/doc/future-3-topologies.md.rsp index 070268dd..739e8145 100644 --- a/revdep/library.noindex/greta/new/future/doc/future-3-topologies.md.rsp +++ b/revdep/library.noindex/greta/new/future/doc/future-3-topologies.md.rsp @@ -102,15 +102,15 @@ Although this does not give an error, we will find that the inner layer of futur Now, we could imagine that we process the outer layer with, say, two parallel futures, and then the inner layer with four parallel futures. In that case, we would end up running on at most eight cores (= 2 * 4). This can be achieved by forcing a fixed number of workers at each layer: ```r -plan(list(tweak(multisession, workers = 2), tweak(multisession, workers = 4))) +plan(list(tweak(multisession, workers = 2), tweak(multisession, workers = I(4)))) ``` -When using this approach, there is a risk of setting up too many concurrent workers. To make sure the setup respects `availableCores()`, use something like: +When using this approach, there is a risk of setting up too many concurrent workers. Because Futureverse has a built-in protection, we need to declare nested workers using the As-Is `I(.)` function, which basically tells the parallel framework "trust us, we know what we are doing". To minimize the risk of mistakes and to make sure our setup respects `availableCores()`, use something like: ```r plan(list( tweak(multisession, workers = availableCores() %/% 4), - tweak(multisession, workers = 4) + tweak(multisession, workers = I(4)) )) ``` @@ -134,7 +134,7 @@ One possible downside to the above setup is that we might not utilize all availa nodes <- rep(c("n1", "n2", "n3"), each = 8) plan(list( tweak(cluster, workers = nodes), - tweak(multisession, workers = 2) + tweak(multisession, workers = I(2)) )) ``` @@ -229,7 +229,7 @@ tweaking the `multisession` plan by passing a function to `workers`; halfCores <- function() { max(1, round(0.5 * availableCores())) plan(list( tweak(cluster, workers = nodes), - tweak(multisession, workers = halfCores) + tweak(multisession, workers = I(halfCores)) )) ``` @@ -250,7 +250,7 @@ customWorkers <- function() { } plan(list( tweak(cluster, workers = nodes), - tweak(multisession, workers = customWorkers) + tweak(multisession, workers = I(customWorkers)) )) ``` diff --git a/revdep/library.noindex/greta/new/future/doc/future-4-non-exportable-objects.html b/revdep/library.noindex/greta/new/future/doc/future-4-non-exportable-objects.html index eb3c88f8..7907c7f5 100644 --- a/revdep/library.noindex/greta/new/future/doc/future-4-non-exportable-objects.html +++ b/revdep/library.noindex/greta/new/future/doc/future-4-non-exportable-objects.html @@ -172,7 +172,7 @@

    A first example - file connections

    The culprit here is that the connection uses a so called external pointer:

    str(con)
     ## Classes 'file', 'connection'  atomic [1:1] 3
    -##   ..- attr(*, "conn_id")=<externalptr> 
    +##   ..- attr(*, "conn_id")=<externalptr>
     

    which is bound to the main R process and makes no sense to the worker. Ideally, the R process of the worker would detect this and produce an informative error message, but as seen here, that does not always occur.

    Protect against non-exportable objects

    @@ -195,10 +195,18 @@

    Packages with non-exportable objec +arrow +Table (externalptr) + + base connection (externalptr) +bigmemory +big.matrix (externalptr) + + cpp11 E.g. functions created by cpp_source() @@ -227,6 +235,10 @@

    Packages with non-exportable objec cluster and cluster nodes (connection) +polars +RPolarsDataFrame (externalptr) + + raster RasterLayer (externalptr; not all) @@ -316,6 +328,96 @@

    Packages that rely on external

    If an object carries an external pointer, it is likely that it can only be used in the R session where it was created. If it is exported to and used in a parallel process, it will likely cause an error there. As shown above, and in below examples, setting option future.globals.onReference to "error" will make future to scan for external pointer:s before launching the future on a parallel worker, and throw an error if one is detected.

    However, there are objects with external pointer:s that can be exported, e.g. data.table objects of the data.table package is one such example. In other words, the existence of a external pointer is just a suggestion for an object being non-exportable - it is not a sufficient condition.

    Below are some examples of packages who produce non-exportable objects with external pointer:s.

    +

    Package: arrow

    +

    The arrow package provides efficient in-memory storage of arrays +and tables. However, these objects cannot be transferred as-is to a +parallel worker.

    +
    library(arrow)
    +
    +library(future)
    +plan(multisession)
    +
    +data <- as_arrow_table(iris)
    +f <- future(dim(data))
    +v <- value(f)
    +#> Error: Invalid <Table>, external pointer to null
    +
    +

    This error takes place on the parallel worker. We could set +options(future.globals.onReference = "error") to have future +detect the problem before it sends the object over to the parallel +worker.

    +

    That said, the arrow package provides low-level functions +write_to_raw() and read_ipc_stream() that can used to marshal and +unmarshal arrow objects. For example,

    +
    library(arrow)
    +
    +library(future)
    +plan(multisession)
    +
    +data <- as_arrow_table(iris)
    +.data <- write_to_raw(data)      ## marshal
    +f <- future({
    +  data <- read_ipc_stream(.data) ## unmarshal
    +  dim(data)
    +})
    +v <- value(f)
    +print(v)
    +#> [1] 150   5
    +
    +

    Package: bigmemory

    +

    The bigmemory package provides mechanisms for working with very +large matrices that can be updated in-place, which helps save +memory. For example,

    +
    library(bigmemory)
    +
    +g <- function(x) {
    +  x[1,1] <- 42L
    +  x
    +}
    +
    +x <- big.matrix(nrow = 3, ncol = 2, type = "integer")
    +print(x[1,1])
    +#> [1] NA
    +
    +void <- g(x)
    +print(x[1,1])
    +#> [1] 42
    +
    +

    Note how x was updated in-place. This is achieved by big.matrix +objects holds an external pointer to where the matrix data is stored;

    +
    str(x)
    +#> Formal class 'big.matrix' [package "bigmemory"] with 1 slot
    +#>   ..@ address:<externalptr> 
    +
    +

    If we would try to use x in a parallel worker, then the parallel +worker crashes due to a bug in bigmemory, e.g.

    +
    library(bigmemory)
    +
    +library(future)
    +plan(multisession, workers = 2)
    +
    +x <- big.matrix(nrow = 3, ncol = 2, type = "integer")
    +f <- future(dim(x), packages = "bigmemory")
    +value(f)
    +#> Error in unserialize(node$con) : 
    +#>   MultisessionFuture (<none>) failed to receive message results from
    +#> cluster RichSOCKnode #1 (PID 1746676 on localhost 'localhost'). The
    +#> reason reported was 'error reading from connection'. Post-mortem
    +#> diagnostic: No process exists with this PID, i.e. the localhost worker
    +#> is no longer alive. Detected a non-exportable reference
    +#> ('externalptr') in one of the globals ('x' of class 'big.matrix') used
    +#> in the future expression. The total size of the 1 globals exported is
    +#> 696 bytes. There is one global: 'x' (696 bytes of class 'S4')
    +
    +

    We can protected against this setting:

    +
    options(future.globals.onReference = "error")
    +
    +

    which gives:

    +
    f <- future(dim(x), packages = "bigmemory")
    +#> Error: Detected a non-exportable reference ('externalptr') in one
    +#> of the globals ('x' of class 'big.matrix') used in the future
    +#> expression
    +

    Package: cpp11

    Another example is cpp11, which allows us to easily create R functions that are implemented in C++, e.g.

    cpp11::cpp_source(code = '
    @@ -339,7 +441,7 @@ 

    Package: cpp11

    x <- rnorm(10) n %<-% my_length(x) n -#> Error in .Call("_code_1748ff617940b9_my_length", x, PACKAGE = "code_1748ff617940b9") : +#> Error in .Call("_code_1748ff617940b9_my_length", x, PACKAGE = "code_1748ff617940b9") : #> "_code_1748ff617940b9_my_length" not available for .Call() for package "code_1748ff617940b9"

    Package: DBI

    @@ -370,7 +472,7 @@

    Package: inline

    plan(cluster, workers = 1L) f <- future(sum_1_to_n(10, 0)) v <- value(f) -## Error in .Primitive(".C")(<pointer: (nil)>, n = as.integer(n), x = as.double(x)) : +## Error in .Primitive(".C")(<pointer: (nil)>, n = as.integer(n), x = as.double(x)) : ## NULL value passed as symbol address

    This is because:

    @@ -408,7 +510,7 @@

    Package: keras

    stats::predict(model, test_input) }, seed = TRUE) pred <- value(f) -## Error in do.call(object$predict, args) : +## Error in do.call(object$predict, args) : ## 'what' must be a function or character string

    This is error message is not very helpful. But, if we turn on @@ -421,9 +523,9 @@

    Package: keras

    Functions serialize_model() and unserialize_model() of the keras package can be used as workaround to marshal and unmarshal non-exportable keras objects, e.g.

    -
    .model <- serialize_model(model)
    +
    .model <- serialize_model(model)      ## marshal
     f <- future({
    -  model <- unserialize_model(.model)
    +  model <- unserialize_model(.model)  ## unmarshal
       stats::predict(model, test_input)
     }, seed = TRUE)
     rm(.model) ## not needed anymore
    @@ -452,6 +554,27 @@ 

    Package: magick

    ## 'magick-image') in one of the globals ('frink' of class 'magick-image') ## used in the future expression
    +

    Package: polars

    +

    The polars package provides objects for performant processing on +tabular data. However, these objects are tied to the R process that +created them. If we attempt to use them in a parallel worker, we end +up crashing the parallel worker:

    +
    library(future)
    +plan(multisession)
    +
    +library(polars)
    +data <- as_polars_df(data.frame(x = 1:3))
    +f <- future(dim(data), packages = "polars")
    +v <- value(f)
    +#> Error: Execution halted with the following contexts
    +#>    0: In R: in `$.RPolarsDataFrame`
    +#>    0: During function call [workRSOCK()]
    +#>    1: This Polars object is not valid. Execute `rm(<object>)` to remove
    +#>       the object or restart the R session.
    +
    +

    This is because the external pointer in the RPolarsDataFrame object +is erased when transferred to another process, which polars (>= 0.15.0) +detects and gives an informative error message about.

    Package: raster

    The raster package provides methods for working with spatial data, which are held in ‘RasterLayer’ objects. Not all but some of these objects use an external pointer. For example,

    library(future)
    @@ -511,7 +634,7 @@ 

    Package: reticulate

    os <- import("os") pwd %<-% os$getcwd() pwd -## Error in eval(quote(os$getcwd()), new.env()) : +## Error in eval(quote(os$getcwd()), new.env()) : ## attempt to apply non-function

    and by telling the future package to validate globals further, we get:

    @@ -527,7 +650,7 @@

    Package: reticulate

    ## [1] 2.4 y %<-% twice(1.2) y -## Error in unserialize(node$con) : +## Error in unserialize(node$con) : ## Failed to retrieve the value of MultisessionFuture from cluster node #1 ## (on 'localhost'). The reason reported was 'error reading from connection'
    @@ -599,7 +722,7 @@

    Package: sparklyr

    data <- spark_read_csv(sc, "exDIF", file) d %<-% dim(data) d -## Error in unserialize(node$con) : +## Error in unserialize(node$con) : ## Failed to retrieve the value of MultisessionFuture (<none>) from cluster ## SOCKnode #1 (PID 29864 on localhost 'localhost'). The reason reported was ## 'unknown input format'. Post-mortem diagnostic: A process with this PID @@ -626,7 +749,7 @@

    Package: terra

    r <- rast(file) dr %<-% dim(r) dr -## Error in .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: (nil)>, : +## Error in .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: (nil)>, : ## NULL value passed as symbol address

    To catch this as soon as possible,

    @@ -642,15 +765,18 @@

    Package: terra

    ## 'RegisteredNativeSymbol') in one of the globals ('r' of class ## 'SpatRaster') used in the future expression -

    Functions wrap() and vect() of the terra package can be used as workaround to marshal and unmarshal non-exportable terra objects, e.g.

    +

    Functions wrap() and unwrap() of the terra package can be used as workaround to marshal and unmarshal non-exportable terra objects, e.g.

    library(future)
     plan(multisession)
     library(terra)
     
     file <- system.file("ex/lux.shp", package = "terra")
     v <- vect(file)
    -.v <- wrap(v)
    -dv %<-% { v <- vect(.v); dim(v) }
    +.v <- wrap(v)      ## marshal
    +dv %<-% {
    +  v <- unwrap(.v)  ## unmarshal
    +  dim(v)
    +}
     rm(.v) ## not needed anymore
     dv
     [1] 12  6
    @@ -658,11 +784,14 @@ 

    Package: terra

    and

    file <- system.file("ex/elev.tif", package = "terra")
     r <- rast(file)
    -.r <- wrap(v)
    -dr %<-% { r <- vect(.r); dim(r) }
    +.r <- wrap(r)      ## marshal
    +dr %<-% {
    +  r <- unwrap(.r)  ## unmarshal
    +  dim(r)
    +}
     rm(.r) ## not needed anymore
     dr
    -[1] 12  6
    +[1] 90 95  1
     

    For more details, see help("wrap", package = "terra").

    Package: udpipe

    @@ -673,7 +802,7 @@

    Package: udpipe

    udmodel <- udpipe_load_model(file = udmodel$file_model) x %<-% udpipe_annotate(udmodel, x = "Ik ging op reis en ik nam mee.") x -## Error in udp_tokenise_tag_parse(object$model, x, doc_id, tokenizer, tagger, : +## Error in udp_tokenise_tag_parse(object$model, x, doc_id, tokenizer, tagger, : ## external pointer is not valid

    To catch this as soon as possible,

    @@ -694,12 +823,12 @@

    Package: xgboost

    class(train) ## [1] "xgb.DMatrix" -d <- dim(dtrain) +d <- dim(train) d ## [1] 6513 126

    works just fine but if we attempt to pass on the ‘xgb.DMatrix’ object train to an external worker, we silently get a incorrect value:

    -
    f <- future(dim(dtrain))
    +
    f <- future(dim(train))
     d <- value(f)
     d
     ## NULL
    @@ -757,7 +886,7 @@ 

    Package: XML

    2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace -Selection: +Selection:

    This is a very harsh way of telling us that we cannot export all types of objects produced by XML. Ideally, XML would detect this @@ -772,9 +901,12 @@

    Package: XML

    a <- getNodeSet(doc, "/doc//a[@status]")[[1]] ## Marshall the non-exportable XMLInternalElementNode object -a_m <- xmlSerializeHook(a) +.a <- xmlSerializeHook(a) ## marshal -f <- future({ a <- xmlDeserializeHook(a_m); xmlGetAttr(a, "status") }) +f <- future({ + a <- xmlDeserializeHook(.a) ## unmarshal + xmlGetAttr(a, "status") +}) value(f) ## [1] "xyz"
    @@ -813,12 +945,12 @@

    Package: xml2

    One workaround when dealing with non-exportable objects is to look for ways to encode the object such that it can be exported, and the decoded on the receiving end. With xml2, we can use xml2::xml_serialize() and xml2::xml_unserialize() to do this. Here is how we can rewrite the above example such that we can pass xml2 object back and forth between the main R session and R workers:

    ## Encode the 'xml_document' object 'doc' as a 'raw' object
    -doc_raw <- xml_serialize(doc, connection = NULL)
    +.doc <- xml_serialize(doc, connection = NULL)  ## marshal
     
     f <- future({
       ## In the future, reconstruct the 'xml_document' object
       ## from the 'raw' object
    -  doc <- xml_unserialize(doc_raw)
    +  doc <- xml_unserialize(.doc)                 ## unmarshal
     
       ## Continue as usual
       children <- xml_children(doc)
    @@ -909,16 +1041,16 @@ 

    Package rstan

    data { int<lower=0> N; real y[N]; -} +} parameters { real mu; -} +} model { target += normal_lpdf(mu | 0, 10); target += normal_lpdf(y | mu, 1); -} +} " y <- rnorm(20) diff --git a/revdep/library.noindex/greta/new/future/doc/future-4-non-exportable-objects.md.rsp b/revdep/library.noindex/greta/new/future/doc/future-4-non-exportable-objects.md.rsp index cf1ef544..3331a72a 100644 --- a/revdep/library.noindex/greta/new/future/doc/future-4-non-exportable-objects.md.rsp +++ b/revdep/library.noindex/greta/new/future/doc/future-4-non-exportable-objects.md.rsp @@ -48,7 +48,7 @@ The culprit here is that the connection uses a so called _external pointer_: ```r str(con) ## Classes 'file', 'connection' atomic [1:1] 3 -## ..- attr(*, "conn_id")= +## ..- attr(*, "conn_id")= ``` which is bound to the main R process and makes no sense to the worker. Ideally, the R process of the worker would detect this and produce an informative error message, but as seen here, that does not always occur. @@ -75,7 +75,9 @@ _If you identify other cases, please consider [reporting](https://github.com/Hen Package | Examples of non-exportable types or classes :---------------|:------------------------------------------- + **arrow** | Table (`externalptr`) **base** | connection (`externalptr`) + **bigmemory** | big.matrix (`externalptr`) **cpp11** | E.g. functions created by `cpp_source()` **DBI** | DBIConnection (`externalptr`) **inline** | CFunc (`externalptr` of class DLLHandle) @@ -83,6 +85,7 @@ _If you identify other cases, please consider [reporting](https://github.com/Hen **magick** | magick-image (`externalptr`) **ncdf4** | ncdf4 (custom reference; _non-detectable_) **parallel** | cluster and cluster nodes (`connection`) + **polars** | RPolarsDataFrame (`externalptr`) **raster** | RasterLayer (`externalptr`; _not all_) **Rcpp** | NativeSymbol (`externalptr`) **reticulate** | python.builtin.function (`externalptr`), python.builtin.module (`externalptr`) @@ -144,6 +147,122 @@ However, there are objects with _external pointer_:s that can be exported, e.g. Below are some examples of packages who produce non-exportable objects with _external pointer_:s. +#### Package: arrow + +The **[arrow]** package provides efficient in-memory storage of arrays +and tables. However, these objects cannot be transferred as-is to a +parallel worker. + +```r +library(arrow) + +library(future) +plan(multisession) + +data <- as_arrow_table(iris) +f <- future(dim(data)) +v <- value(f) +#> Error: Invalid , external pointer to null +``` + +This error takes place on the parallel worker. We could set +`options(future.globals.onReference = "error")` to have **future** +detect the problem before it sends the object over to the parallel +worker. + +That said, the **arrow** package provides low-level functions +`write_to_raw()` and `read_ipc_stream()` that can used to marshal and +unmarshal **arrow** objects. For example, + +```r +library(arrow) + +library(future) +plan(multisession) + +data <- as_arrow_table(iris) +.data <- write_to_raw(data) ## marshal +f <- future({ + data <- read_ipc_stream(.data) ## unmarshal + dim(data) +}) +v <- value(f) +print(v) +#> [1] 150 5 +``` + + +#### Package: bigmemory + +The **[bigmemory]** package provides mechanisms for working with very +large matrices that can be updated in-place, which helps save +memory. For example, + +```r +library(bigmemory) + +g <- function(x) { + x[1,1] <- 42L + x +} + +x <- big.matrix(nrow = 3, ncol = 2, type = "integer") +print(x[1,1]) +#> [1] NA + +void <- g(x) +print(x[1,1]) +#> [1] 42 +``` + +Note how `x` was updated in-place. This is achieved by `big.matrix` +objects holds an external pointer to where the matrix data is stored; + +```r +str(x) +#> Formal class 'big.matrix' [package "bigmemory"] with 1 slot +#> ..@ address: +``` + +If we would try to use `x` in a parallel worker, then the parallel +worker crashes due to a bug in **bigmemory**, e.g. + +```r +library(bigmemory) + +library(future) +plan(multisession, workers = 2) + +x <- big.matrix(nrow = 3, ncol = 2, type = "integer") +f <- future(dim(x), packages = "bigmemory") +value(f) +#> Error in unserialize(node$con) : +#> MultisessionFuture () failed to receive message results from +#> cluster RichSOCKnode #1 (PID 1746676 on localhost 'localhost'). The +#> reason reported was 'error reading from connection'. Post-mortem +#> diagnostic: No process exists with this PID, i.e. the localhost worker +#> is no longer alive. Detected a non-exportable reference +#> ('externalptr') in one of the globals ('x' of class 'big.matrix') used +#> in the future expression. The total size of the 1 globals exported is +#> 696 bytes. There is one global: 'x' (696 bytes of class 'S4') +``` + +We can protected against this setting: + +```r +options(future.globals.onReference = "error") +``` + +which gives: + +```r +f <- future(dim(x), packages = "bigmemory") +#> Error: Detected a non-exportable reference ('externalptr') in one +#> of the globals ('x' of class 'big.matrix') used in the future +#> expression +``` + + #### Package: cpp11 Another example is **[cpp11]**, which allows us to easily create R functions that are implemented in C++, e.g. @@ -176,7 +295,7 @@ plan(multisession) x <- rnorm(10) n %<-% my_length(x) n -#> Error in .Call("_code_1748ff617940b9_my_length", x, PACKAGE = "code_1748ff617940b9") : +#> Error in .Call("_code_1748ff617940b9_my_length", x, PACKAGE = "code_1748ff617940b9") : #> "_code_1748ff617940b9_my_length" not available for .Call() for package "code_1748ff617940b9" ``` @@ -220,7 +339,7 @@ library(future) plan(cluster, workers = 1L) f <- future(sum_1_to_n(10, 0)) v <- value(f) -## Error in .Primitive(".C")(, n = as.integer(n), x = as.double(x)) : +## Error in .Primitive(".C")(, n = as.integer(n), x = as.double(x)) : ## NULL value passed as symbol address ``` @@ -266,7 +385,7 @@ f <- future({ stats::predict(model, test_input) }, seed = TRUE) pred <- value(f) -## Error in do.call(object$predict, args) : +## Error in do.call(object$predict, args) : ## 'what' must be a function or character string ``` @@ -285,9 +404,9 @@ Functions `serialize_model()` and `unserialize_model()` of the non-exportable **keras** objects, e.g. ```r -.model <- serialize_model(model) +.model <- serialize_model(model) ## marshal f <- future({ - model <- unserialize_model(.model) + model <- unserialize_model(.model) ## unmarshal stats::predict(model, test_input) }, seed = TRUE) rm(.model) ## not needed anymore @@ -329,6 +448,33 @@ we'll see that this is caught even before attempting to run this in parallel; ``` +#### Package: polars + +The **[polars]** package provides objects for performant processing on +tabular data. However, these objects are tied to the R process that +created them. If we attempt to use them in a parallel worker, we end +up crashing the parallel worker: + +```r +library(future) +plan(multisession) + +library(polars) +data <- as_polars_df(data.frame(x = 1:3)) +f <- future(dim(data), packages = "polars") +v <- value(f) +#> Error: Execution halted with the following contexts +#> 0: In R: in `$.RPolarsDataFrame` +#> 0: During function call [workRSOCK()] +#> 1: This Polars object is not valid. Execute `rm()` to remove +#> the object or restart the R session. +``` + +This is because the external pointer in the `RPolarsDataFrame` object +is erased when transferred to another process, which **polars** (>= 0.15.0) +detects and gives an informative error message about. + + #### Package: raster The **[raster]** package provides methods for working with spatial data, which are held in 'RasterLayer' objects. Not all but some of these objects use an external pointer. For example, @@ -411,7 +557,7 @@ library(reticulate) os <- import("os") pwd %<-% os$getcwd() pwd -## Error in eval(quote(os$getcwd()), new.env()) : +## Error in eval(quote(os$getcwd()), new.env()) : ## attempt to apply non-function ``` @@ -433,7 +579,7 @@ twice(1.2) ## [1] 2.4 y %<-% twice(1.2) y -## Error in unserialize(node$con) : +## Error in unserialize(node$con) : ## Failed to retrieve the value of MultisessionFuture from cluster node #1 ## (on 'localhost'). The reason reported was 'error reading from connection' ``` @@ -531,7 +677,7 @@ file <- system.file("misc", "exDIF.csv", package = "utils") data <- spark_read_csv(sc, "exDIF", file) d %<-% dim(data) d -## Error in unserialize(node$con) : +## Error in unserialize(node$con) : ## Failed to retrieve the value of MultisessionFuture () from cluster ## SOCKnode #1 (PID 29864 on localhost 'localhost'). The reason reported was ## 'unknown input format'. Post-mortem diagnostic: A process with this PID @@ -565,7 +711,7 @@ file <- system.file("ex/elev.tif", package = "terra") r <- rast(file) dr %<-% dim(r) dr -## Error in .External(list(name = "CppMethod__invoke_notvoid", address = , : +## Error in .External(list(name = "CppMethod__invoke_notvoid", address = , : ## NULL value passed as symbol address ``` @@ -585,7 +731,7 @@ dr %<-% dim(data) ## 'SpatRaster') used in the future expression ``` -Functions `wrap()` and `vect()` of the **terra** package can be used as workaround to marshal and unmarshal non-exportable **terra** objects, e.g. +Functions `wrap()` and `unwrap()` of the **terra** package can be used as workaround to marshal and unmarshal non-exportable **terra** objects, e.g. ```r library(future) @@ -594,8 +740,11 @@ library(terra) file <- system.file("ex/lux.shp", package = "terra") v <- vect(file) -.v <- wrap(v) -dv %<-% { v <- vect(.v); dim(v) } +.v <- wrap(v) ## marshal +dv %<-% { + v <- unwrap(.v) ## unmarshal + dim(v) +} rm(.v) ## not needed anymore dv [1] 12 6 @@ -606,11 +755,14 @@ and ```r file <- system.file("ex/elev.tif", package = "terra") r <- rast(file) -.r <- wrap(v) -dr %<-% { r <- vect(.r); dim(r) } +.r <- wrap(r) ## marshal +dr %<-% { + r <- unwrap(.r) ## unmarshal + dim(r) +} rm(.r) ## not needed anymore dr -[1] 12 6 +[1] 90 95 1 ``` For more details, see `help("wrap", package = "terra")`. @@ -626,7 +778,7 @@ udmodel <- udpipe_download_model(language = "dutch") udmodel <- udpipe_load_model(file = udmodel$file_model) x %<-% udpipe_annotate(udmodel, x = "Ik ging op reis en ik nam mee.") x -## Error in udp_tokenise_tag_parse(object$model, x, doc_id, tokenizer, tagger, : +## Error in udp_tokenise_tag_parse(object$model, x, doc_id, tokenizer, tagger, : ## external pointer is not valid ``` @@ -656,7 +808,7 @@ train <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label) class(train) ## [1] "xgb.DMatrix" -d <- dim(dtrain) +d <- dim(train) d ## [1] 6513 126 ``` @@ -664,7 +816,7 @@ d works just fine but if we attempt to pass on the 'xgb.DMatrix' object `train` to an external worker, we silently get a incorrect value: ```r -f <- future(dim(dtrain)) +f <- future(dim(train)) d <- value(f) d ## NULL @@ -734,7 +886,7 @@ Possible actions: 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace -Selection: +Selection: ``` This is a very harsh way of telling us that we cannot export all types @@ -753,9 +905,12 @@ doc <- xmlParse(system.file("exampleData", "tagnames.xml", package = "XML")) a <- getNodeSet(doc, "/doc//a[@status]")[[1]] ## Marshall the non-exportable XMLInternalElementNode object -a_m <- xmlSerializeHook(a) +.a <- xmlSerializeHook(a) ## marshal -f <- future({ a <- xmlDeserializeHook(a_m); xmlGetAttr(a, "status") }) +f <- future({ + a <- xmlDeserializeHook(.a) ## unmarshal + xmlGetAttr(a, "status") +}) value(f) ## [1] "xyz" ``` @@ -808,12 +963,12 @@ One workaround when dealing with non-exportable objects is to look for ways to e ```r ## Encode the 'xml_document' object 'doc' as a 'raw' object -doc_raw <- xml_serialize(doc, connection = NULL) +.doc <- xml_serialize(doc, connection = NULL) ## marshal f <- future({ ## In the future, reconstruct the 'xml_document' object ## from the 'raw' object - doc <- xml_unserialize(doc_raw) + doc <- xml_unserialize(.doc) ## unmarshal ## Continue as usual children <- xml_children(doc) @@ -938,16 +1093,16 @@ code <- " data { int N; real y[N]; -} +} parameters { real mu; -} +} model { target += normal_lpdf(mu | 0, 10); target += normal_lpdf(y | mu, 1); -} +} " y <- rnorm(20) @@ -987,12 +1142,15 @@ str(e) [data.table]: https://cran.r-project.org/package=data.table +[arrow]: https://cran.r-project.org/package=arrow +[bigmemory]: https://cran.r-project.org/package=bigmemory [cpp11]: https://cran.r-project.org/package=cpp11 [DBI]: https://cran.r-project.org/package=DBI [inline]: https://cran.r-project.org/package=inline [keras]: https://cran.r-project.org/package=DBI [magick]: https://cran.r-project.org/package=magick [ncdf4]: https://cran.r-project.org/package=ncdf4 +[polars]: https://rpolars.github.io/ [raster]: https://cran.r-project.org/package=raster [Rcpp]: https://cran.r-project.org/package=Rcpp [reticulate]: https://cran.r-project.org/package=reticulate diff --git a/revdep/library.noindex/greta/new/future/doc/future-7-for-package-developers.html b/revdep/library.noindex/greta/new/future/doc/future-7-for-package-developers.html index 152fdcc7..86e16e97 100644 --- a/revdep/library.noindex/greta/new/future/doc/future-7-for-package-developers.html +++ b/revdep/library.noindex/greta/new/future/doc/future-7-for-package-developers.html @@ -216,6 +216,17 @@

    Avoid changing the future strategy

    and let the user control whether or not they want to parallelize via plan(), e.g. plan(multisession) and plan(sequential).

    +

    Avoid changing the future options

    +

    Just like for other R options, you must not change any of the R +future.* options. Only the end-user should set these.

    +

    If you find yourself having to tweak one of the options, make sure to +undo your changes immediately afterward. For example, if you want to +bump up the future.globals.maxSize limit when creating a future, +use something like the following inside your function:

    +
    oopts <- options(future.globals.maxSize = 1.0 * 1e9)  ## 1.0 GB
    +on.exit(options(oopts))
    +f <- future({ expr })  ## Launch a future with large objects
    +

    Writing examples

    If your example sets the future strategy at the beginning, make sure to reset the future strategy to plan(sequential) at the end of the example. The reason for this is that when switching plan, the previous one will be cleaned up. This is particularly important for multisession and cluster futures where plan(sequential) will shut down the underlying PSOCK clusters.

    For instance, here is an example:

    diff --git a/revdep/library.noindex/greta/new/future/doc/future-7-for-package-developers.md.rsp b/revdep/library.noindex/greta/new/future/doc/future-7-for-package-developers.md.rsp index dfb9e50a..4ecd5fdd 100644 --- a/revdep/library.noindex/greta/new/future/doc/future-7-for-package-developers.md.rsp +++ b/revdep/library.noindex/greta/new/future/doc/future-7-for-package-developers.md.rsp @@ -127,6 +127,23 @@ my_fcn <- function(x) { and let the user control whether or not they want to parallelize via `plan()`, e.g. `plan(multisession)` and `plan(sequential)`. +## Avoid changing the future options + +Just like for other R options, you must not change any of the R +`future.*` options. Only the end-user should set these. + +If you find yourself having to tweak one of the options, make sure to +undo your changes immediately afterward. For example, if you want to +bump up the `future.globals.maxSize` limit when creating a future, +use something like the following inside your function: + +```r +oopts <- options(future.globals.maxSize = 1.0 * 1e9) ## 1.0 GB +on.exit(options(oopts)) +f <- future({ expr }) ## Launch a future with large objects +``` + + ## Writing examples If your example sets the future strategy at the beginning, make sure to reset the future strategy to `plan(sequential)` at the end of the example. The reason for this is that when switching plan, the previous one will be cleaned up. This is particularly important for multisession and cluster futures where `plan(sequential)` will shut down the underlying PSOCK clusters. diff --git a/revdep/library.noindex/greta/new/future/doc/future-8-how-future-is-validated.html b/revdep/library.noindex/greta/new/future/doc/future-8-how-future-is-validated.html index 74ec2ba5..867131c9 100644 --- a/revdep/library.noindex/greta/new/future/doc/future-8-how-future-is-validated.html +++ b/revdep/library.noindex/greta/new/future/doc/future-8-how-future-is-validated.html @@ -88,7 +88,7 @@

    A Future for R: Ho future, globals, and listenv, implement a rich set of package tests. These are validated regularly across the wide-range of operating systems (Linux, Solaris, macOS, and MS Windows) and R versions available -on CRAN, via continuous integration (CI) (GitHub Actions), and on R-hub.

    +on CRAN, via continuous integration (CI) (GitHub Actions), and on R-hub.

    Second, for each new release, these packages undergo full reverse-package dependency checks using revdepcheck. As of June 2022, the future package is tested against 240+ diff --git a/revdep/library.noindex/greta/new/future/doc/future-8-how-future-is-validated.md.rsp b/revdep/library.noindex/greta/new/future/doc/future-8-how-future-is-validated.md.rsp index 8273e701..55e96224 100644 --- a/revdep/library.noindex/greta/new/future/doc/future-8-how-future-is-validated.md.rsp +++ b/revdep/library.noindex/greta/new/future/doc/future-8-how-future-is-validated.md.rsp @@ -91,4 +91,4 @@ of the _Future API_ and the future ecosystem at large. [revdepcheck]: https://github.com/r-lib/revdepcheck [GitHub Actions]: https://github.com/features/actions -[R-hub]: https://builder.r-hub.io/ +[R-hub]: https://r-hub.github.io/rhub/ diff --git a/revdep/library.noindex/greta/new/future/help/AnIndex b/revdep/library.noindex/greta/new/future/help/AnIndex index fd06d393..792dbe60 100644 --- a/revdep/library.noindex/greta/new/future/help/AnIndex +++ b/revdep/library.noindex/greta/new/future/help/AnIndex @@ -42,6 +42,7 @@ future.fork.multithreading.enable future.options future.globalenv.onMisuse future.options future.globals.maxSize future.options future.globals.method future.options +future.globals.objectSize.method future.options future.globals.onMissing future.options future.globals.onReference future.options future.globals.resolve future.options @@ -115,6 +116,7 @@ R_FUTURE_FORK_MULTITHREADING_ENABLE future.options R_FUTURE_GLOBALENV_ONMISUSE future.options R_FUTURE_GLOBALS_MAXSIZE future.options R_FUTURE_GLOBALS_METHOD future.options +R_FUTURE_GLOBALS_OBJECTSIZE_METHOD future.options R_FUTURE_GLOBALS_ONMISSING future.options R_FUTURE_GLOBALS_ONREFERENCE future.options R_FUTURE_GLOBALS_RESOLVE future.options diff --git a/revdep/library.noindex/greta/new/future/help/aliases.rds b/revdep/library.noindex/greta/new/future/help/aliases.rds index 9555a48c..22817824 100644 Binary files a/revdep/library.noindex/greta/new/future/help/aliases.rds and b/revdep/library.noindex/greta/new/future/help/aliases.rds differ diff --git a/revdep/library.noindex/greta/new/future/help/future.rdb b/revdep/library.noindex/greta/new/future/help/future.rdb index 7dbc3ec8..0a24b0b2 100644 Binary files a/revdep/library.noindex/greta/new/future/help/future.rdb and b/revdep/library.noindex/greta/new/future/help/future.rdb differ diff --git a/revdep/library.noindex/greta/new/future/help/future.rdx b/revdep/library.noindex/greta/new/future/help/future.rdx index b9fa96f1..bf7a55d0 100644 Binary files a/revdep/library.noindex/greta/new/future/help/future.rdx and b/revdep/library.noindex/greta/new/future/help/future.rdx differ diff --git a/revdep/library.noindex/greta/new/future/help/paths.rds b/revdep/library.noindex/greta/new/future/help/paths.rds index 241ca4c4..8f3515e6 100644 Binary files a/revdep/library.noindex/greta/new/future/help/paths.rds and b/revdep/library.noindex/greta/new/future/help/paths.rds differ diff --git a/revdep/library.noindex/greta/new/future/html/00Index.html b/revdep/library.noindex/greta/new/future/html/00Index.html index e43a758e..3068697a 100644 --- a/revdep/library.noindex/greta/new/future/html/00Index.html +++ b/revdep/library.noindex/greta/new/future/html/00Index.html @@ -12,7 +12,7 @@

    Unified Parallel and Distributed Processing in R for Everyone
    [Up] [Top] -

    Documentation for package ‘future’ version 1.33.1

    +

    Documentation for package ‘future’ version 1.34.0

    + + @@ -154,6 +156,8 @@

    Help Pages

    + + diff --git a/revdep/library.noindex/greta/new/greta/DESCRIPTION b/revdep/library.noindex/greta/new/greta/DESCRIPTION index dbb8244b..cf3880ad 100644 --- a/revdep/library.noindex/greta/new/greta/DESCRIPTION +++ b/revdep/library.noindex/greta/new/greta/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: greta Title: Simple and Scalable Statistical Modelling in R -Version: 0.4.4 +Version: 0.5.0 Authors@R: c( person("Nick", "Golding", , "nick.golding.research@gmail.com", role = "aut", comment = c(ORCID = "0000-0001-8916-5570")), @@ -28,23 +28,24 @@ Description: Write statistical models in R and fit them by MCMC and including tutorials, examples, package documentation, and the greta forum. License: Apache License 2.0 -URL: https://greta-stats.org +URL: https://greta-stats.org, https://github.com/greta-dev/greta BugReports: https://github.com/greta-dev/greta/issues -Depends: R (>= 3.1.0) -Imports: abind, callr, cli (>= 3.0.0), coda, future (>= 1.22.1), glue +Depends: R (>= 4.1.0) +Imports: abind, callr, cli (>= 3.4.1), coda, future (>= 1.22.1), glue (>= 1.5.1), methods, parallelly (>= 1.29.0), progress (>= - 1.2.0), R6, reticulate (>= 1.19.0), tensorflow (>= 2.7.0), - yesno -Suggests: bayesplot, covr, cramer, DiagrammeR, extraDistr, fields, - ggplot2, knitr, lattice, MASS, MCMCpack, mockery, mvtnorm, - rmarkdown, rmutil, spelling, testthat (>= 3.1.0), tidyverse, - truncdist, withr + 1.2.0), R6, reticulate (>= 1.19.0), rlang, tensorflow (== + 2.16.0), tools, utils, whisker, yesno +Suggests: bayesplot, covr, cramer, DiagrammeR, dplyr, DiagrammeRsvg, + extraDistr, fields, ggplot2, knitr, lattice, MASS, MCMCpack, + mockery, mvtnorm, purrr, rmarkdown, rmutil, rsvg, spelling, + testthat (>= 3.1.0), tibble, tidyr, truncdist, withr, + rstudioapi VignetteBuilder: knitr Config/testthat/edition: 3 Encoding: UTF-8 -Language: en-GB +Language: en-US Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.2 SystemRequirements: Python (>= 2.7.0) with header files and shared library; TensorFlow (v1.14; https://www.tensorflow.org/); TensorFlow Probability (v0.7.0; @@ -55,19 +56,20 @@ Collate: 'package.R' 'utils.R' 'greta_mcmc_list.R' 'tf_functions.R' 'unknowns_class.R' 'greta_array_class.R' 'as_data.R' 'distribution.R' 'operators.R' 'functions.R' 'transforms.R' 'structures.R' 'extract_replace_combine.R' 'dag_class.R' - 'greta_model_class.R' 'progress_bar.R' 'inference_class.R' - 'samplers.R' 'optimisers.R' 'inference.R' - 'install_tensorflow.R' 'calculate.R' 'callbacks.R' 'simulate.R' - 'chol2symm.R' 'install_greta_deps.R' 'conda_greta_env.R' - 'greta_stash.R' 'greta_create_conda_env.R' - 'greta_install_miniconda.R' 'greta_install_python_deps.R' - 'new_install_process.R' 'reinstallers.R' 'checkers.R' - 'test_if_forked_cluster.R' 'testthat-helpers.R' 'zzz.R' - 'internals.R' + 'data-deps-tf-tfp.R' 'greta_model_class.R' 'progress_bar.R' + 'inference_class.R' 'samplers.R' 'optimisers.R' + 'optimiser_class.R' 'inference.R' 'install_tensorflow.R' + 'calculate.R' 'callbacks.R' 'simulate.R' 'chol2symm.R' + 'install_greta_deps.R' 'conda_greta_env.R' 'greta_stash.R' + 'greta_create_conda_env.R' 'greta_install_miniconda.R' + 'greta_install_python_deps.R' 'new_install_process.R' + 'reinstallers.R' 'checkers.R' 'test_if_forked_cluster.R' + 'testthat-helpers.R' 'write-logfiles.R' 'zzz.R' 'internals.R' +LazyData: true RemoteType: local RemoteUrl: /Users/nick/github/greta-dev/greta NeedsCompilation: no -Packaged: 2024-01-16 03:05:29 UTC; nick +Packaged: 2024-11-08 04:41:32 UTC; nick Author: Nick Golding [aut] (), Nicholas Tierney [aut, cre] (), Simon Dirmeier [ctb], @@ -83,4 +85,4 @@ Author: Nick Golding [aut] (), Paul Teetor [ctb], Jian Yen [ctb] Maintainer: Nicholas Tierney -Built: R 4.3.2; ; 2024-01-16 03:05:32 UTC; unix +Built: R 4.4.2; ; 2024-11-08 04:41:33 UTC; unix diff --git a/revdep/library.noindex/greta/new/greta/INDEX b/revdep/library.noindex/greta/new/greta/INDEX index d2cb2787..fb49abd8 100644 --- a/revdep/library.noindex/greta/new/greta/INDEX +++ b/revdep/library.noindex/greta/new/greta/INDEX @@ -1,30 +1,57 @@ +are_null Vectorised is.null +as.greta_model Convert object to a "greta_model" object +as.unknowns Create objects of class 'unknowns' to nicely + print ? valued arrays as_data convert other objects to greta arrays calculate calculate greta arrays given fixed values +chol.greta_array Compute the Cholesky Factor of a Matrix chol2symm Cholesky Factor to Symmetric Matrix +destroy_greta_deps Remove greta dependencies and remove miniconda +dim.node generic to grab dimensions of nodes +dim<-.unknowns set dims like on a matrix/array distribution define a distribution over data distributions probability distributions extract-replace-combine extract, replace and combine greta arrays functions functions for greta arrays +gpu_cpu Set GPU or CPU usage greta greta: simple and scalable statistical modelling in R -greta_notes_install_miniconda_output - Retrieve python installation or error details. +greta_create_conda_env + Create conda environment for greta +greta_deps_receipt Capture greta python dependencies. +greta_deps_spec Specify python dependencies for greta +greta_deps_tf_tfp Suggested valid Python dependencies for greta +greta_install_miniconda + Installs miniconda +greta_notes_tf_num_error + Retrieve python messages. +greta_set_install_logfile + Set logfile path when installing greta greta_sitrep Greta Situation Report inference Statistical inference on greta models. install_greta_deps Install Python dependencies for greta internals internal greta methods +is.greta_array Is object a greta array? +is.greta_mcmc_list Is object a 'greta_mcmc_list'? joint define joint distributions mixture mixtures of probability distributions model greta model objects +open_greta_install_log + Read a greta logfile operators arithmetic, logical and relational operators for greta arrays optimisers optimisation methods overloaded Functions overloaded by greta +print.greta_deps_spec Print method for greta python deps +print.greta_mcmc_list Print method for greta MCMC list reinstallers Helpers to remove, and reinstall python environments and miniconda +run_optimiser Dispatch optimisation method to right class samplers MCMC samplers simulate.greta_model Simulate Responses From 'greta_model' Object structures create data greta arrays transforms transformation functions for greta arrays variable create greta variables +write_greta_install_log + Write greta dependency installation log file diff --git a/revdep/library.noindex/greta/new/greta/Meta/Rd.rds b/revdep/library.noindex/greta/new/greta/Meta/Rd.rds index f6a7ec5d..7b7aedc0 100644 Binary files a/revdep/library.noindex/greta/new/greta/Meta/Rd.rds and b/revdep/library.noindex/greta/new/greta/Meta/Rd.rds differ diff --git a/revdep/library.noindex/greta/new/greta/Meta/features.rds b/revdep/library.noindex/greta/new/greta/Meta/features.rds index b8114a5f..85226dc4 100644 Binary files a/revdep/library.noindex/greta/new/greta/Meta/features.rds and b/revdep/library.noindex/greta/new/greta/Meta/features.rds differ diff --git a/revdep/library.noindex/greta/new/greta/Meta/hsearch.rds b/revdep/library.noindex/greta/new/greta/Meta/hsearch.rds index b466cdd7..dfb3ef53 100644 Binary files a/revdep/library.noindex/greta/new/greta/Meta/hsearch.rds and b/revdep/library.noindex/greta/new/greta/Meta/hsearch.rds differ diff --git a/revdep/library.noindex/greta/new/greta/Meta/links.rds b/revdep/library.noindex/greta/new/greta/Meta/links.rds index 29a41afc..584ff5f9 100644 Binary files a/revdep/library.noindex/greta/new/greta/Meta/links.rds and b/revdep/library.noindex/greta/new/greta/Meta/links.rds differ diff --git a/revdep/library.noindex/greta/new/greta/Meta/nsInfo.rds b/revdep/library.noindex/greta/new/greta/Meta/nsInfo.rds index 499c1546..d995646b 100644 Binary files a/revdep/library.noindex/greta/new/greta/Meta/nsInfo.rds and b/revdep/library.noindex/greta/new/greta/Meta/nsInfo.rds differ diff --git a/revdep/library.noindex/greta/new/greta/Meta/package.rds b/revdep/library.noindex/greta/new/greta/Meta/package.rds index 3badd41e..04e47b0f 100644 Binary files a/revdep/library.noindex/greta/new/greta/Meta/package.rds and b/revdep/library.noindex/greta/new/greta/Meta/package.rds differ diff --git a/revdep/library.noindex/greta/new/greta/NAMESPACE b/revdep/library.noindex/greta/new/greta/NAMESPACE index 767031e7..1c8276ea 100644 --- a/revdep/library.noindex/greta/new/greta/NAMESPACE +++ b/revdep/library.noindex/greta/new/greta/NAMESPACE @@ -106,6 +106,8 @@ S3method(mean,greta_array) S3method(min,greta_array) S3method(plot,greta_model) S3method(print,greta_array) +S3method(print,greta_deps_spec) +S3method(print,greta_mcmc_list) S3method(print,greta_model) S3method(print,initials) S3method(print,optimiser) @@ -122,6 +124,9 @@ S3method(rowMeans,default) S3method(rowMeans,greta_array) S3method(rowSums,default) S3method(rowSums,greta_array) +S3method(run_optimiser,tf_compat_optimiser) +S3method(run_optimiser,tf_optimiser) +S3method(run_optimiser,tfp_optimiser) S3method(sign,greta_array) S3method(simulate,greta_model) S3method(sin,greta_array) @@ -151,7 +156,11 @@ export(adadelta) export(adagrad) export(adagrad_da) export(adam) +export(adamax) export(apply) +export(are_null) +export(as.greta_model) +export(as.unknowns) export(as_data) export(backsolve) export(bernoulli) @@ -171,6 +180,8 @@ export(cobyla) export(colMeans) export(colSums) export(cov2cor) +export(cpu_only) +export(destroy_greta_deps) export(diag) export(dirichlet) export(dirichlet_multinomial) @@ -182,15 +193,15 @@ export(f) export(forwardsolve) export(ftrl) export(gamma) +export(gpu_only) export(gradient_descent) export(greta_array) -export(greta_notes_conda_create_error) -export(greta_notes_conda_create_output) -export(greta_notes_conda_install_error) -export(greta_notes_conda_install_output) -export(greta_notes_install_miniconda_error) -export(greta_notes_install_miniconda_output) +export(greta_create_conda_env) +export(greta_deps_receipt) +export(greta_deps_spec) +export(greta_install_miniconda) export(greta_notes_tf_num_error) +export(greta_set_install_logfile) export(greta_sitrep) export(hmc) export(hypergeometric) @@ -204,6 +215,8 @@ export(install_greta_deps) export(install_tensorflow) export(inverse_gamma) export(iprobit) +export(is.greta_array) +export(is.greta_mcmc_list) export(joint) export(l_bfgs_b) export(laplace) @@ -217,11 +230,13 @@ export(model) export(momentum) export(multinomial) export(multivariate_normal) +export(nadam) export(negative_binomial) export(nelder_mead) export(newton_cg) export(normal) export(ones) +export(open_greta_install_log) export(opt) export(ordered_variable) export(pareto) @@ -238,6 +253,7 @@ export(remove_miniconda) export(rms_prop) export(rowMeans) export(rowSums) +export(run_optimiser) export(rwmh) export(simplex_variable) export(slice) @@ -251,6 +267,7 @@ export(uniform) export(variable) export(weibull) export(wishart) +export(write_greta_install_log) export(zeros) import(methods) importFrom(R6,R6Class) @@ -290,6 +307,7 @@ importFrom(stats,runif) importFrom(stats,simulate) importFrom(stats,start) importFrom(stats,window) +importFrom(tensorflow,"%as%") importFrom(tensorflow,dict) importFrom(tensorflow,install_tensorflow) importFrom(tensorflow,shape) diff --git a/revdep/library.noindex/greta/new/greta/NEWS.md b/revdep/library.noindex/greta/new/greta/NEWS.md index a73e762a..b16019cf 100644 --- a/revdep/library.noindex/greta/new/greta/NEWS.md +++ b/revdep/library.noindex/greta/new/greta/NEWS.md @@ -1,3 +1,99 @@ +# greta 0.5.0 + +This version of greta uses Tensorflow 2.0.0, which comes with it a host of new very exciting features! + +## Optimizers + +The latest interface to optimizers in tensorflow are now used, these changes are described. + +* `gradient_descent` gains `momentum` and `nesterov` arguments, as described here in [TF docs](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/SGD) +* `adagrad` gains [`epsilon` argument](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adagrad) +* removes `momentum` optimizer, as this has been folded into `gradient_descent` arguments +* Adds `amsgrad` argument to `adam` optimizer, as described in [TF docs](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adam) +* Adds `adamax` optimiser, see [TF docs](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Adamax) +* Adds `l2_shrinkage_regularization_strength` and `beta` arguments to `ftrl` + optimiser. +* adds `nadam` optimiser - see [docs](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/Nadam). +* In `rms_prop` optimiser, changes `decay` parameter to `rho`, and adds `centered` parameter - see [docs](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/RMSprop) + +The following optimisers are removed, as they are no longer supported by Tensorflow: + + * `powell()` + * `cg()` + * `newton_cg()` + * `l_bfgs_b()` + * `tnc()` + * `cobyla()` + * `slsqp()` + +## Installation revamp + +This release provides a few improvements to installation in greta. It should now provide more information about installation progress, and be more robust. The intention is, it should _just work_, and if it doesn't, it should fail gracefully with some useful advice on problem solving. + +* Added option to restart R + run `library(greta)` after installation (#523). +* Added installation deps object, `greta_deps_sepc()` to help simplify specifying package versions (#664). +* Removed `method` and `conda` arguments from `install_greta_deps()` as they + were not used. +* Removed `manual` argument in `install_greta_deps()`. +* Added default 5 minute timer to installation processes. +* Added `greta_deps_receipt()` to list the current main python packages installed (#668). +* Added checking suite to ensure you are using valid versions of TF, TFP, and Python(#666). +* Added data `greta_deps_tf_tfp` (#666), which contains valid versions combinations of TF, TFP, and Python. +* Remove `greta_nodes_install/conda_*()` options as #493 makes them defunct. +* Added option to write to a single logfile with `greta_set_install_logfile()`, and `write_greta_install_log()`, and `open_greta_install_log()` (#493). +* Added `destroy_greta_deps()` function to remove miniconda and python conda environment. +* Improved `write_greta_install_log()` and `open_greta_install_log()` to use `tools::R_user_dir()` to always write to a file location. `open_greta_install_log()` will open one found from an environment variable or go to the default location (#703). + +## New Print methods + +* New print method for `greta_mcmc_list`. This means MCMC output will be shorter and more informative (#644). +* greta arrays now have a print method that stops them from printing too many rows into the console. Similar to MCMC print method, you can control the print output with the `n` argument: `print(object, n = )` (#644). + +## Minor + +* `greta_sitrep()` now checks for installations of Python, TF, and TFP. +* Slice sampler no longer needs precision = "single" to work. +* greta now depends on R 4.1.0, which was released May 2021, over 3 years ago. +* export `is.greta_array()` and `is.greta_mcmc_list()`. +* `restart` argument for `install_greta_deps()` and `reinstall_greta_deps()` to automatically restart R (#523). + +## Internals + +* Internally we are replacing most of the error handling code as separate + `check_*` functions. +* Implemented `cli::cli_abort/warn/inform()` in place of `cli::format_error/warning/message()` + `stop/warning/message(msg, call. = FALSE)` pattern. +* Uses legacy optimizer internally (Use `tf$keras$optimizers$legacy$METHOD` over `tf$keras$optimizers$METHOD`). No user impact expected. +* Update photo of Grete Hermann (#598). +* Use `%||%` internally to replace the pattern: `if (is.null(x)) x <- thing` with `x <- x %||% thing` (#630). +* Add more explaining variables - replace `if (thing & thing & what == this)` with `if (explanation_of_thing)`. +* Refactored repeated uses of `vapply` into functions (#377, #658). +* Add internal data files `.deps_tf` and `.deps_tfp` to track dependencies of TF and TFP. Related to #666. + +- Posterior density checks (#720): + - Don't run Geweke on CI as it takes 30 minutes to run. + - Add thinning to Geweke tests. + - Fix broken geweke tests from TF1-->TF2 change. + - Increase the number of effective samples for check_samples for lkj distribution + - Add more checks to posterior to run on CI/on each test of greta + +## Bug fixes + +* Fix bug where matrix multiply had dimension error before coercing to greta array. (#464) +- Fixes for Wishart and LKJ Correlation distributions (#729 #733 #734): + - Add bijection density to choleskied distributions. + - Note about some issues with LKJ and our normalisation constant for the density. + - Removed our custom `forward_log_det_jacobian()` function from `tf_correlation_cholesky_bijector()` (used in `lkj_correlation()`). Previously, it did not work with unknown dimensions, but it now works with them. + - Ensure wishart uses sigma_chol in scale_tril + - Wishart uses `tf$matmul(chol_draws, chol_draws, adjoint_b = TRUE)` instead of `tf_chol2symm(chol_draws)`. + - Test log prob function returns valid numeric numbers. + - Addresses issue with log prob returning NaNs--replace `FillTriangular` with `FillScaleTriL` and apply Chaining to first transpose input. + +# greta 0.4.5 + +## Bug Fixes + +- Remove trailing comma bug in glue #618 + # greta 0.4.4 ## Bug fixes diff --git a/revdep/library.noindex/greta/new/greta/R/greta.rdb b/revdep/library.noindex/greta/new/greta/R/greta.rdb index 6b6d1393..ea256b22 100644 Binary files a/revdep/library.noindex/greta/new/greta/R/greta.rdb and b/revdep/library.noindex/greta/new/greta/R/greta.rdb differ diff --git a/revdep/library.noindex/greta/new/greta/R/greta.rdx b/revdep/library.noindex/greta/new/greta/R/greta.rdx index dfec27eb..6ff16412 100644 Binary files a/revdep/library.noindex/greta/new/greta/R/greta.rdx and b/revdep/library.noindex/greta/new/greta/R/greta.rdx differ diff --git a/revdep/library.noindex/greta/new/greta/WORDLIST b/revdep/library.noindex/greta/new/greta/WORDLIST index c971b48e..731a7864 100644 --- a/revdep/library.noindex/greta/new/greta/WORDLIST +++ b/revdep/library.noindex/greta/new/greta/WORDLIST @@ -1,73 +1,150 @@ +AMSGrad AVX +AdagradDAOptimiser CMD CRAN's +Cmd Codecov -Conda +Ctrl DAGs DiagrammeR +GPUs GPflow +Gao Gelman Geweke Greh Grete HMC -Inf +Hermann +Hessians +JIT Jupyter +LKJ Lmax Lmin +McMahan Miniconda +Modelling Nesterov NumPy ORCID OpenBUGS +Optimizers PSAT -Poisson -R's +ProximalAdagradOptimizer +ProximalGradientDescentOptimizer +README RStudio RStudio's -SciPy +Scalable TF -TensorFlow -TensorFlow's +TFP Tensorflow +Vectorised WinBUGS XLA +acyclic +al +analysed +args +automagically bayesplot +behaviour +bijection +broadcastable +broadcasted +chol +choleskied cholesky cli +colour +colours conda -cran -dag +dependences +deps devtools dlkjcorr doi dontrun +dtype env -etc +equalling +et extraDistr +generalises +geweke gfortran github greta's gretaDynamics +hager +helpfile igraph +initialised +initialises +initialising +joss +labelled libxml +linux +lkj +logfile +logfiles +maximise mcmc md miniconda +misspecified +modelled +modelling +multisession nd -numpy +normalisation +normalised +optimisation +optimisations +optimiser +optimisers +optimizers ouputs -parameterisations +parallelisation +parallelise +parallelising pkgdown poisson polygamma +posteriori +priori +pythonic +realisation +realisations +recoded +regularisation +reinstalls +repo +reproducibility +rescale +rescaled +rescaling +reticulate +scalable schoolers softmax -speedup -st +specialised +summarise tensorflow +tensorflows +tf +tfp +tril tuh +unadjusted +uncentered uncoached -virtualenv +vectorising +visualise warmup winbuilder +wishart +zhang diff --git a/revdep/library.noindex/greta/new/greta/help/AnIndex b/revdep/library.noindex/greta/new/greta/help/AnIndex index 309db382..6af032cf 100644 --- a/revdep/library.noindex/greta/new/greta/help/AnIndex +++ b/revdep/library.noindex/greta/new/greta/help/AnIndex @@ -6,7 +6,11 @@ adadelta optimisers adagrad optimisers adagrad_da optimisers adam optimisers +adamax optimisers apply overloaded +are_null are_null +as.greta_model as.greta_model +as.unknowns as.unknowns as_data as_data backsolve overloaded bernoulli distributions @@ -21,6 +25,7 @@ cauchy distributions cbind extract-replace-combine cg optimisers chi_squared distributions +chol.greta_array chol.greta_array chol2inv overloaded chol2symm chol2symm cholesky_variable variable @@ -28,7 +33,11 @@ cobyla optimisers colMeans overloaded colSums overloaded cov2cor overloaded +cpu_only gpu_cpu +destroy_greta_deps destroy_greta_deps diag overloaded +dim.node dim.node +dim<-.unknowns dim-set-.unknowns dirichlet distributions dirichlet_multinomial distributions distribution distribution @@ -44,16 +53,18 @@ forwardsolve overloaded ftrl optimisers functions functions gamma distributions +gpu_cpu gpu_cpu +gpu_only gpu_cpu gradient_descent optimisers greta greta greta_array structures -greta_notes_conda_create_error stash-notes -greta_notes_conda_create_output stash-notes -greta_notes_conda_install_error stash-notes -greta_notes_conda_install_output stash-notes -greta_notes_install_miniconda_error stash-notes -greta_notes_install_miniconda_output stash-notes +greta_create_conda_env greta_create_conda_env +greta_deps_receipt greta_deps_receipt +greta_deps_spec greta_deps_spec +greta_deps_tf_tfp greta_deps_tf_tfp +greta_install_miniconda greta_install_miniconda greta_notes_tf_num_error stash-notes +greta_set_install_logfile greta_set_install_logfile greta_sitrep greta_sitrep hmc samplers hypergeometric distributions @@ -70,6 +81,8 @@ internals internals inverse-links transforms inverse_gamma distributions iprobit transforms +is.greta_array is.greta_array +is.greta_mcmc_list is.greta_mcmc_list joint joint laplace distributions lkj_correlation distributions @@ -83,11 +96,13 @@ model model momentum optimisers multinomial distributions multivariate_normal distributions +nadam optimisers negative_binomial distributions nelder_mead optimisers newton_cg optimisers normal distributions ones structures +open_greta_install_log open_greta_install_log operators operators opt inference optimisers optimisers @@ -97,6 +112,8 @@ pareto distributions plot.greta_model model poisson distributions powell optimisers +print.greta_deps_spec print.greta_deps_spec +print.greta_mcmc_list print.greta_mcmc_list print.greta_model model proximal_adagrad optimisers proximal_gradient_descent optimisers @@ -114,13 +131,13 @@ replace extract-replace-combine rms_prop optimisers rowMeans overloaded rowSums overloaded +run_optimiser run_optimiser rwmh samplers samplers samplers simplex_variable variable simulate.greta_model simulate.greta_model slice samplers slsqp optimisers -stash-notes stash-notes stashed_samples inference structures structures student distributions @@ -132,4 +149,5 @@ uniform distributions variable variable weibull distributions wishart distributions +write_greta_install_log write_greta_install_log zeros structures diff --git a/revdep/library.noindex/greta/new/greta/help/aliases.rds b/revdep/library.noindex/greta/new/greta/help/aliases.rds index e86310e3..d2c15d65 100644 Binary files a/revdep/library.noindex/greta/new/greta/help/aliases.rds and b/revdep/library.noindex/greta/new/greta/help/aliases.rds differ diff --git a/revdep/library.noindex/greta/new/greta/help/greta.rdb b/revdep/library.noindex/greta/new/greta/help/greta.rdb index d57be2cf..4e0f8209 100644 Binary files a/revdep/library.noindex/greta/new/greta/help/greta.rdb and b/revdep/library.noindex/greta/new/greta/help/greta.rdb differ diff --git a/revdep/library.noindex/greta/new/greta/help/greta.rdx b/revdep/library.noindex/greta/new/greta/help/greta.rdx index ffe56264..780b8e92 100644 Binary files a/revdep/library.noindex/greta/new/greta/help/greta.rdx and b/revdep/library.noindex/greta/new/greta/help/greta.rdx differ diff --git a/revdep/library.noindex/greta/new/greta/help/paths.rds b/revdep/library.noindex/greta/new/greta/help/paths.rds index acf83638..2acf6393 100644 Binary files a/revdep/library.noindex/greta/new/greta/help/paths.rds and b/revdep/library.noindex/greta/new/greta/help/paths.rds differ diff --git a/revdep/library.noindex/greta/new/greta/html/00Index.html b/revdep/library.noindex/greta/new/greta/html/00Index.html index e109b336..517a89e8 100644 --- a/revdep/library.noindex/greta/new/greta/html/00Index.html +++ b/revdep/library.noindex/greta/new/greta/html/00Index.html @@ -12,7 +12,7 @@

    Simple and Scalable Statistical Modelling in R
    [Up] [Top] -

    Documentation for package ‘greta’ version 0.4.4

    +

    Documentation for package ‘greta’ version 0.5.0

    + + + + + + + +
    Options used for futures
    future.globals.method Options used for futures
    future.globals.objectSize.methodOptions used for futures
    future.globals.onMissing Options used for futures
    future.globals.onReference Options used for futures
    R_FUTURE_GLOBALS_METHOD Options used for futures
    R_FUTURE_GLOBALS_OBJECTSIZE_METHODOptions used for futures
    R_FUTURE_GLOBALS_ONMISSING Options used for futures
    R_FUTURE_GLOBALS_ONREFERENCEoptimisation methods
    adam optimisation methods
    adamaxoptimisation methods
    apply Functions overloaded by greta
    are_nullVectorised is.null
    as.greta_modelConvert object to a "greta_model" object
    as.unknownsCreate objects of class 'unknowns' to nicely print ? valued arrays
    as_data convert other objects to greta arrays
    @@ -106,6 +114,8 @@

    -- C --

    optimisation methods chi_squared probability distributions +chol.greta_array +Compute the Cholesky Factor of a Matrix chol2inv Functions overloaded by greta chol2symm @@ -120,13 +130,21 @@

    -- C --

    Functions overloaded by greta cov2cor Functions overloaded by greta +cpu_only +Set GPU or CPU usage

    -- D --

    + + + + + + @@ -172,26 +190,30 @@

    -- G --

    destroy_greta_depsRemove greta dependencies and remove miniconda
    diag Functions overloaded by greta
    dim.nodegeneric to grab dimensions of nodes
    dim<-.unknownsset dims like on a matrix/array
    dirichlet probability distributions
    dirichlet_multinomial
    + + + + - - - - - - - - - - - - + + + + + + + + + + - + + +
    gamma probability distributions
    gpu_cpuSet GPU or CPU usage
    gpu_onlySet GPU or CPU usage
    gradient_descent optimisation methods
    greta greta: simple and scalable statistical modelling in R
    greta_array create data greta arrays
    greta_notes_conda_create_errorRetrieve python installation or error details.
    greta_notes_conda_create_outputRetrieve python installation or error details.
    greta_notes_conda_install_errorRetrieve python installation or error details.
    greta_notes_conda_install_outputRetrieve python installation or error details.
    greta_notes_install_miniconda_errorRetrieve python installation or error details.
    greta_notes_install_miniconda_outputRetrieve python installation or error details.
    greta_create_conda_envCreate conda environment for greta
    greta_deps_receiptCapture greta python dependencies.
    greta_deps_specSpecify python dependencies for greta
    greta_deps_tf_tfpSuggested valid Python dependencies for greta
    greta_install_minicondaInstalls miniconda
    greta_notes_tf_num_errorRetrieve python installation or error details.
    Retrieve python messages.
    greta_set_install_logfileSet logfile path when installing greta
    greta_sitrep Greta Situation Report
    @@ -232,6 +254,10 @@

    -- I --

    probability distributions iprobit transformation functions for greta arrays +is.greta_array +Is object a greta array? +is.greta_mcmc_list +Is object a 'greta_mcmc_list'?

    -- J --

    @@ -278,6 +304,8 @@

    -- M --

    -- N --

    + + @@ -293,6 +321,8 @@

    -- O --

    nadamoptimisation methods
    negative_binomial probability distributions
    nelder_mead
    + + @@ -316,6 +346,10 @@

    -- P --

    + + + + @@ -353,6 +387,8 @@

    -- R --

    + +
    ones create data greta arrays
    open_greta_install_logRead a greta logfile
    operators arithmetic, logical and relational operators for greta arrays
    opt probability distributions
    powell optimisation methods
    print.greta_deps_specPrint method for greta python deps
    print.greta_mcmc_listPrint method for greta MCMC list
    print.greta_model greta model objects
    proximal_adagrad Functions overloaded by greta
    rowSums Functions overloaded by greta
    run_optimiserDispatch optimisation method to right class
    rwmh MCMC samplers
    @@ -370,8 +406,6 @@

    -- S --

    MCMC samplers slsqp optimisation methods -stash-notes -Retrieve python installation or error details. stashed_samples Statistical inference on greta models. structures @@ -414,6 +448,8 @@

    -- W --

    probability distributions wishart probability distributions +write_greta_install_log +Write greta dependency installation log file

    -- Z --

    diff --git a/revdep/library.noindex/greta/old/greta/CITATION b/revdep/library.noindex/greta/old/greta/CITATION index f857195c..45bbb6b7 100644 --- a/revdep/library.noindex/greta/old/greta/CITATION +++ b/revdep/library.noindex/greta/old/greta/CITATION @@ -1,8 +1,8 @@ citHeader("To cite greta in publications use:") -citEntry(entry = "Article", +bibentry(bibtype = "Article", title = "{greta}: simple and scalable statistical modelling in R", - author = personList(as.person("Nick Golding")), + author = c(person(given = "Nick", family = "Golding", email = "nick.golding.research@gmail.com")), journal = "Journal of Open Source Software", year = "2019", volume = "4", diff --git a/revdep/library.noindex/greta/old/greta/DESCRIPTION b/revdep/library.noindex/greta/old/greta/DESCRIPTION index a84b135c..d9ea9245 100644 --- a/revdep/library.noindex/greta/old/greta/DESCRIPTION +++ b/revdep/library.noindex/greta/old/greta/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: greta Title: Simple and Scalable Statistical Modelling in R -Version: 0.4.3 +Version: 0.4.5 Authors@R: c( person("Nick", "Golding", , "nick.golding.research@gmail.com", role = "aut", comment = c(ORCID = "0000-0001-8916-5570")), @@ -35,15 +35,15 @@ Imports: abind, callr, cli (>= 3.0.0), coda, future (>= 1.22.1), glue (>= 1.5.1), methods, parallelly (>= 1.29.0), progress (>= 1.2.0), R6, reticulate (>= 1.19.0), tensorflow (>= 2.7.0), yesno -Suggests: bayesplot, covr, cramer, DiagrammeR, extraDistr, fields, - ggplot2, knitr, lattice, MASS, MCMCpack, mockery, mvtnorm, - rmarkdown, rmutil, spelling, testthat (>= 3.1.0), tidyverse, - truncdist, withr +Suggests: bayesplot, covr, cramer, DiagrammeR, DiagrammeRsvg, + extraDistr, fields, ggplot2, knitr, lattice, MASS, MCMCpack, + mockery, mvtnorm, rmarkdown, rmutil, rsvg, spelling, testthat + (>= 3.1.0), tidyverse, truncdist, withr VignetteBuilder: knitr Config/testthat/edition: 3 Encoding: UTF-8 Language: en-GB -RoxygenNote: 7.2.0 +RoxygenNote: 7.3.1 SystemRequirements: Python (>= 2.7.0) with header files and shared library; TensorFlow (v1.14; https://www.tensorflow.org/); TensorFlow Probability (v0.7.0; @@ -64,7 +64,7 @@ Collate: 'package.R' 'utils.R' 'greta_mcmc_list.R' 'tf_functions.R' 'test_if_forked_cluster.R' 'testthat-helpers.R' 'zzz.R' 'internals.R' NeedsCompilation: no -Packaged: 2022-09-08 13:42:15 UTC; njtierney +Packaged: 2024-03-11 06:20:23 UTC; nick Author: Nick Golding [aut] (), Nicholas Tierney [aut, cre] (), Simon Dirmeier [ctb], @@ -81,5 +81,5 @@ Author: Nick Golding [aut] (), Jian Yen [ctb] Maintainer: Nicholas Tierney Repository: CRAN -Date/Publication: 2022-09-08 14:12:56 UTC -Built: R 4.3.0; ; 2023-07-10 04:59:54 UTC; unix +Date/Publication: 2024-03-11 08:10:02 UTC +Built: R 4.4.0; ; 2024-04-06 10:05:44 UTC; unix diff --git a/revdep/library.noindex/greta/old/greta/INDEX b/revdep/library.noindex/greta/old/greta/INDEX index 2a334c4e..d2cb2787 100644 --- a/revdep/library.noindex/greta/old/greta/INDEX +++ b/revdep/library.noindex/greta/old/greta/INDEX @@ -9,9 +9,9 @@ functions functions for greta arrays greta greta: simple and scalable statistical modelling in R greta_notes_install_miniconda_output - Retrieve python installation or error details + Retrieve python installation or error details. greta_sitrep Greta Situation Report -inference statistical inference on greta models +inference Statistical inference on greta models. install_greta_deps Install Python dependencies for greta internals internal greta methods joint define joint distributions diff --git a/revdep/library.noindex/greta/old/greta/Meta/Rd.rds b/revdep/library.noindex/greta/old/greta/Meta/Rd.rds index e0ca9585..2c343ae7 100644 Binary files a/revdep/library.noindex/greta/old/greta/Meta/Rd.rds and b/revdep/library.noindex/greta/old/greta/Meta/Rd.rds differ diff --git a/revdep/library.noindex/greta/old/greta/Meta/features.rds b/revdep/library.noindex/greta/old/greta/Meta/features.rds index 97f580d7..ded31532 100644 Binary files a/revdep/library.noindex/greta/old/greta/Meta/features.rds and b/revdep/library.noindex/greta/old/greta/Meta/features.rds differ diff --git a/revdep/library.noindex/greta/old/greta/Meta/hsearch.rds b/revdep/library.noindex/greta/old/greta/Meta/hsearch.rds index a4fa88b9..e1ef5940 100644 Binary files a/revdep/library.noindex/greta/old/greta/Meta/hsearch.rds and b/revdep/library.noindex/greta/old/greta/Meta/hsearch.rds differ diff --git a/revdep/library.noindex/greta/old/greta/Meta/links.rds b/revdep/library.noindex/greta/old/greta/Meta/links.rds index de5b8c39..113dee74 100644 Binary files a/revdep/library.noindex/greta/old/greta/Meta/links.rds and b/revdep/library.noindex/greta/old/greta/Meta/links.rds differ diff --git a/revdep/library.noindex/greta/old/greta/Meta/nsInfo.rds b/revdep/library.noindex/greta/old/greta/Meta/nsInfo.rds index cf68a186..482f2a68 100644 Binary files a/revdep/library.noindex/greta/old/greta/Meta/nsInfo.rds and b/revdep/library.noindex/greta/old/greta/Meta/nsInfo.rds differ diff --git a/revdep/library.noindex/greta/old/greta/Meta/package.rds b/revdep/library.noindex/greta/old/greta/Meta/package.rds index 4b4dcd4d..04edb806 100644 Binary files a/revdep/library.noindex/greta/old/greta/Meta/package.rds and b/revdep/library.noindex/greta/old/greta/Meta/package.rds differ diff --git a/revdep/library.noindex/greta/old/greta/Meta/vignette.rds b/revdep/library.noindex/greta/old/greta/Meta/vignette.rds index 71328768..992ef11e 100644 Binary files a/revdep/library.noindex/greta/old/greta/Meta/vignette.rds and b/revdep/library.noindex/greta/old/greta/Meta/vignette.rds differ diff --git a/revdep/library.noindex/greta/old/greta/NAMESPACE b/revdep/library.noindex/greta/old/greta/NAMESPACE index f0bdbda2..767031e7 100644 --- a/revdep/library.noindex/greta/old/greta/NAMESPACE +++ b/revdep/library.noindex/greta/old/greta/NAMESPACE @@ -20,6 +20,7 @@ S3method("[",greta_array) S3method("[<-",greta_array) S3method("^",greta_array) S3method("dim<-",greta_array) +S3method("dim<-",unknowns) S3method("|",greta_array) S3method(Arg,greta_array) S3method(Conj,greta_array) @@ -42,8 +43,12 @@ S3method(as.greta_array,logical) S3method(as.greta_array,matrix) S3method(as.greta_array,node) S3method(as.greta_array,numeric) +S3method(as.greta_model,dag_class) S3method(as.matrix,greta_array) S3method(as.mcmc.list,greta_mcmc_list) +S3method(as.unknowns,array) +S3method(as.unknowns,matrix) +S3method(as.unknowns,unknowns) S3method(as_data,default) S3method(as_data,greta_array) S3method(asin,greta_array) @@ -77,6 +82,7 @@ S3method(diag,default) S3method(diag,greta_array) S3method(digamma,greta_array) S3method(dim,greta_array) +S3method(dim,node) S3method(eigen,default) S3method(eigen,greta_array) S3method(exp,greta_array) diff --git a/revdep/library.noindex/greta/old/greta/NEWS.md b/revdep/library.noindex/greta/old/greta/NEWS.md index d5fc77ea..27c8543c 100644 --- a/revdep/library.noindex/greta/old/greta/NEWS.md +++ b/revdep/library.noindex/greta/old/greta/NEWS.md @@ -1,3 +1,15 @@ +# greta 0.4.5 + +## Bug Fixes + +- Remove trailing comma bug in glue #618 + +# greta 0.4.4 + +## Bug fixes + +- Some small documentation bugs were fixed, namely the sentinel "_PACKAGE" documentation, and various small changes to correctly export S3 methods. + # greta 0.4.3 ## Features diff --git a/revdep/library.noindex/greta/old/greta/R/greta.rdb b/revdep/library.noindex/greta/old/greta/R/greta.rdb index e1caf34b..3a670104 100644 Binary files a/revdep/library.noindex/greta/old/greta/R/greta.rdb and b/revdep/library.noindex/greta/old/greta/R/greta.rdb differ diff --git a/revdep/library.noindex/greta/old/greta/R/greta.rdx b/revdep/library.noindex/greta/old/greta/R/greta.rdx index 8dc7242e..0ba32af2 100644 Binary files a/revdep/library.noindex/greta/old/greta/R/greta.rdx and b/revdep/library.noindex/greta/old/greta/R/greta.rdx differ diff --git a/revdep/library.noindex/greta/old/greta/WORDLIST b/revdep/library.noindex/greta/old/greta/WORDLIST index ec50e653..c971b48e 100644 --- a/revdep/library.noindex/greta/old/greta/WORDLIST +++ b/revdep/library.noindex/greta/old/greta/WORDLIST @@ -15,10 +15,10 @@ Inf Jupyter Lmax Lmin -Maëlle Miniconda Nesterov NumPy +ORCID OpenBUGS PSAT Poisson @@ -31,7 +31,6 @@ TensorFlow TensorFlow's Tensorflow WinBUGS -Wujciak XLA bayesplot cholesky @@ -63,7 +62,6 @@ pkgdown poisson polygamma schoolers -snapshotting softmax speedup st diff --git a/revdep/library.noindex/greta/old/greta/doc/example_models.R b/revdep/library.noindex/greta/old/greta/doc/example_models.R index 60c84318..32833559 100644 --- a/revdep/library.noindex/greta/old/greta/doc/example_models.R +++ b/revdep/library.noindex/greta/old/greta/doc/example_models.R @@ -4,580 +4,3 @@ knitr::opts_chunk$set(comment = NA, cache = TRUE) library (greta) -## ----linear_greta------------------------------------------------------------- -# variables & priors -int <- normal(0, 10) -coef <- normal(0, 10) -sd <- cauchy(0, 3, truncation = c(0, Inf)) - -# linear predictor -mu <- int + coef * attitude$complaints - -# observation model -distribution(attitude$rating) <- normal(mu, sd) - -## ----multiple_linear_data----------------------------------------------------- -data(attitude) -design <- as.matrix(attitude[, 2:7]) - -## ----multiple_linear_greta---------------------------------------------------- -int <- normal(0, 10) -coefs <- normal(0, 10, dim = ncol(design)) -sd <- cauchy(0, 3, truncation = c(0, Inf)) - -# matrix multiplication is more efficient than multiplying the coefficients -# separately -mu <- int + design %*% coefs - -distribution(attitude$rating) <- normal(mu, sd) - -## ----multiple_linear_warpbreaks_data------------------------------------------ -data("warpbreaks") -X <- as_data(model.matrix(breaks ~ wool + tension, warpbreaks)) -y <- as_data(warpbreaks$breaks) - -## ----multiple_linear_warpbreaks_greta----------------------------------------- -int <- variable() -coefs <- normal(0, 5, dim = ncol(X) - 1) -beta <- c(int, coefs) - -eta <- X %*% beta - -distribution(y) <- poisson(exp(eta)) - -## ----multiple_linear_multilogit_data------------------------------------------ -data(iris) -X <- as_data(cbind(1, iris[, 1:4])) -y <- model.matrix(~ Species - 1, iris) -P <- ncol(X) -K <- ncol(y) - -## ----multiple_linear_multilogit_greta----------------------------------------- -beta <- normal(0, 5, dim = c(P, K - 1)) -eta <- X %*% beta -prob <- imultilogit(eta) -distribution(y) <- categorical(prob) - -## ----multiple_linear_lasso_data----------------------------------------------- -data(attitude) -design <- as.matrix(attitude[, 2:7]) - -## ----multiple_linear_lasso_greta---------------------------------------------- -int <- normal(0, 10) -sd <- cauchy(0, 3, truncation = c(0, Inf)) - -tau <- exponential(0.5, dim = ncol(design)) -coefs <- normal(0, tau) -mu <- int + design %*% coefs - -distribution(attitude$rating) <- normal(mu, sd) - -## ----hierarchical_linear_greta------------------------------------------------ -# linear model parameters -int <- normal(0, 10) -coef <- normal(0, 10) -sd <- cauchy(0, 3, truncation = c(0, Inf)) - -# hierarchical model for species effect; use the first species as the baseline -# like in lm() -species_sd <- lognormal(0, 1) -species_offset <- normal(0, species_sd, dim = 2) -species_effect <- rbind(0, species_offset) -species_id <- as.numeric(iris$Species) - -# model -mu <- int + coef * iris$Sepal.Width + species_effect[species_id] -distribution(iris$Sepal.Length) <- normal(mu, sd) - -## ----hierarchical_linear_slopes_greta----------------------------------------- -# linear model parameters -int <- normal(0, 10) -coef <- normal(0, 10) -sd <- cauchy(0, 3, truncation = c(0, Inf)) - -species_id <- as.numeric(iris$Species) - -# random intercepts -species_int_sd <- lognormal(0, 1) -species_int <- normal(0, species_int_sd, dim = 2) -species_int_eff <- rbind(0, species_int) - -# random slopes -species_slope_sd <- lognormal(0, 1) -species_slope <- normal(0, species_slope_sd, dim = 2) -species_slope_eff <- rbind(0, species_slope) - -# model -mu <- int + coef * iris$Sepal.Width + species_int_eff[species_id] + iris$Sepal.Width * species_slope_eff[species_id] -distribution(iris$Sepal.Length) <- normal(mu, sd) - -## ----hierarchical_linear_slopes_corr_greta------------------------------------ -# model matrix -modmat <- model.matrix(~ Sepal.Width, iris) -# index of species -jj <- as.numeric(iris$Species) - -M <- ncol(modmat) # number of varying coefficients -N <- max(jj) # number of species - -# prior on the standard deviation of the varying coefficient -tau <- exponential(0.5, dim = M) - -# prior on the correlation between the varying coefficient -Omega <- lkj_correlation(3, M) - -# optimization of the varying coefficient sampling through -# cholesky factorization and whitening -Omega_U <- chol(Omega) -Sigma_U <- sweep(Omega_U, 2, tau, "*") -z <- normal(0, 1, dim = c(N, M)) -ab <- z %*% Sigma_U # equivalent to: ab ~ multi_normal(0, Sigma_U) - -# the linear predictor -mu <- rowSums(ab[jj,] * modmat) - -# the residual variance -sigma_e <- cauchy(0, 3, truncation = c(0, Inf)) - -#model -y <- iris$Sepal.Length -distribution(y) <- normal(mu, sigma_e) - -## ----linear_uninformative_greta----------------------------------------------- -# variables & priors -int <- variable() -coef <- variable() -sd <- cauchy(0, 3, truncation = c(0, Inf)) - -# linear predictor -mu <- int + coef * attitude$complaints - -# observation model -distribution(attitude$rating) <- normal(mu, sd) - -## ----linear_ridge_greta------------------------------------------------------- -# variables & priors -int <- variable() -sd <- cauchy(0, 3, truncation = c(0, Inf)) - -tau <- inverse_gamma(1, 1) -coef <- normal(0, tau) - -# linear predictor -mu <- int + coef * attitude$complaints - -# observation model -distribution(attitude$rating) <- normal(mu, sd) - -## ----linear_lasso_greta------------------------------------------------------- -# variables & priors -int <- variable() -sd <- inverse_gamma(1, 1) - -lambda <- gamma(1, 1) -tau <- exponential(0.5 * lambda**2) -coef <- normal(0, tau) - -# linear predictor -mu <- int + coef * attitude$complaints - -# observation model -distribution(attitude$rating) <- normal(mu, sd) - -## ----linear_horseshoe_greta--------------------------------------------------- -horseshoe <- function (tau = 1, dim = NULL) { - lambda <- cauchy(0, 1, truncation = c(0, Inf), dim = dim) - sd <- tau ^ 2 * lambda ^ 2 - normal(0, sd, dim = dim) -} - -# variables & priors -int <- variable() -sd <- inverse_gamma(1, 1) -coef <- horseshoe() - -# linear predictor -mu <- int + coef * attitude$complaints - -# observation model -distribution(attitude$rating) <- normal(mu, sd) - -## ----linear_finnish_horseshoe_greta------------------------------------------- -regularized_horseshoe <- function (tau = 1, c = 1, dim = NULL) { - stopifnot(c > 0) - lambda <- cauchy(0, 1, truncation = c(0, Inf), dim = dim) - lambda_tilde <- (c^2 * lambda^2) / (c^2 + tau^2 * lambda^2) - sd <- tau ^ 2 * lambda_tilde ^ 2 - normal(0, sd, dim = dim) -} - -# variables & priors -int <- variable() -sd <- inverse_gamma(1, 1) -coef <- regularized_horseshoe() - -# linear predictor -mu <- int + coef * attitude$complaints - -# observation model -distribution(attitude$rating) <- normal(mu, sd) - -## ----hierarchical_linear_general_greta---------------------------------------- -int <- normal(0, 10) -coef <- normal(0, 10) -sd <- cauchy(0, 3, truncation = c(0, Inf)) - -n_species <- length(unique(iris$Species)) -species_id <- as.numeric(iris$Species) - -Z <- model.matrix(~ Species + Sepal.Length * Species - 1, data = iris) - -gamma_matrix <- multivariate_normal(matrix(0, 1, 2), - diag(2), - n_realisations = 3) -gamma <- c(gamma_matrix) - -wi <- as_data(iris$Sepal.Width) -Z <- as_data(Z) -mu <- int + coef * wi + Z %*% gamma - -distribution(iris$Sepal.Length) <- normal(mu, sd) - -## ----hierarchical_linear_marginal_greta--------------------------------------- -int <- variable() -coef <- normal(0, 5) -sd <- cauchy(0, 3, truncation = c(0, Inf)) - -n_species <- length(unique(iris$Species)) -species_id <- as.numeric(iris$Species) - -Z <- model.matrix(~ Species + Sepal.Length * Species - 1, data = iris) -G <- zeros(n_species * 2, n_species * 2) - -for (s in unique(species_id)) { - G[c(s, s + n_species), c(s, s + n_species)] <- diag(2) -} - -mu <- int + coef * iris$Sepal.Width -V <- zeros(nrow(iris), nrow(iris)) -diag(V) <- sd - -Z <- as_data(Z) -V <- V + Z %*% G %*% t(Z) - -sep <- t(iris$Sepal.Width) -distribution(sep) <- multivariate_normal(t(mu), V) - -## ----bayesian_neural_network_data, highlight = FALSE-------------------------- -N <- 100 -p <- 10 - -set.seed(23) -X <- matrix(rnorm(N * p), N) -beta <- rnorm(10) -y <- X %*% beta + rnorm(N, sd = 0.1) - -## ----bayesian_neural_network_greta-------------------------------------------- -neural_network <- function(x) -{ - # this can be arbitrarily complex, e.g. multiple hidden layers - x %*% weights -} - -weights <- normal(0, 1, dim = c(p, 1)) -sd <- inverse_gamma(1, 1) - -distribution(y) <- normal(neural_network(X), sd) - -## ----factor_analysis_data, highlight = FALSE---------------------------------- -generate.data <- function(n = 100, p = 5, q = 2, psi = diag(rgamma(p, 1, 1))) -{ - W <- matrix(rnorm(p * q, 1), p, q) - Z <- matrix(rnorm(q * n, 2), q, n) - WZ <- W %*% Z - - X <- matrix(0, n, p) - for (i in seq_len(n)) { - X[i, ] <- MASS::mvrnorm(1, WZ[, i], psi) - } - - list(X = X, W = W, Z = Z, psi = psi) -} - -n <- 100 -p <- 5 -q <- 2 -data <- generate.data(n = n, p = p, q = q) -X <- data$X - -## ----factor_analysis---------------------------------------------------------- -W <- normal(0, 1, dim = c(p, q)) -Z <- normal(0, 1, dim = c(q, n)) -psi <- zeros(p, p) -diag(psi) <- inverse_gamma(1, 1, dim = p) - -distribution(X) <- multivariate_normal(t(W %*% Z), psi) - -## ----air_data, highlight = FALSE---------------------------------------------- -y <- c(21, 20, 15) -n <- c(48, 34, 21) -Z <- c(10, 30, 50) -alpha <- 4.48 -beta <- 0.76 -sigma2 <- 81.14 -sigma <- sqrt(sigma2) -tau <- 1 / sigma2 -J <- 3 - -## ----air_greta---------------------------------------------------------------- -theta <- normal(0, 32, dim = 2) -mu <- alpha + beta * Z -X <- normal(mu, sigma) -p <- ilogit(theta[1] + theta[2] * X) -distribution(y) <- binomial(n, p) - -## ----air_stan, echo = FALSE--------------------------------------------------- -cat(readLines('https://raw.githubusercontent.com/stan-dev/example-models/master/bugs_examples/vol2/air/air.stan'), sep = '\n') - -## ----beetles_data, highlight = FALSE------------------------------------------ -x <- c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, 1.8839) -n <- c(59, 60, 62, 56, 63, 59, 62, 60) -r <- c(6, 13, 18, 28, 52, 53, 61, 60) -N <- 8 - -## ----beetles_greta------------------------------------------------------------ -alpha_star <- normal(0, 32) -beta <- normal(0, 32) -p <- ilogit(alpha_star + beta * (x - mean(x))) -distribution(r) <- binomial(n, p) - -alpha <- alpha_star - beta * mean(x) -rhat <- p * n - -## ----beetles_stan, echo = FALSE----------------------------------------------- -cat(readLines('https://raw.githubusercontent.com/stan-dev/example-models/master/bugs_examples/vol2/beetles/beetles_logit.stan'), sep = '\n') - -## ----lightspeed_data, highlight = FALSE--------------------------------------- -y <- c(28, 26, 33, 24, 34, -44, 27, 16, 40, -2, 29, 22, 24, 21, 25, - 30, 23, 29, 31, 19, 24, 20, 36, 32, 36, 28, 25, 21, 28, 29, - 37, 25, 28, 26, 30, 32, 36, 26, 30, 22, 36, 23, 27, 27, 28, - 27, 31, 27, 26, 33, 26, 32, 32, 24, 39, 28, 24, 25, 32, 25, - 29, 27, 28, 29, 16, 23) -n <- length(y) - -## ----lightspeed_greta--------------------------------------------------------- -beta <- variable() -sigma <- variable(lower = 0) - -distribution(y) <- normal(beta, sigma) - -## ----lightspeed_stan, echo = FALSE-------------------------------------------- -cat(readLines('https://raw.githubusercontent.com/stan-dev/example-models/master/ARM/Ch.8/lightspeed.stan'), sep = '\n') - -## ----schools_data, highlight = FALSE------------------------------------------ -y <- c(28, 8, -3, 7, -1, 1, 18, 12) -sigma_y <- c(15, 10, 16, 11, 9, 11, 10, 18) -N <- length(y) - -## ----schools_greta------------------------------------------------------------ -sigma_eta <- inverse_gamma(1, 1) -eta <- normal(0, sigma_eta, dim=N) - -mu_theta <- normal(0, 100) -xi <- normal(0, 5) -theta <- mu_theta + xi * eta - -distribution(y) <- normal(theta, sigma_y) - -## ----schools_stan, echo = FALSE----------------------------------------------- -cat(readLines('https://raw.githubusercontent.com/stan-dev/example-models/master/ARM/Ch.19/schools.stan'), sep = '\n') - -## ----data_logistic, highlight = FALSE----------------------------------------- -# make fake data -n_env <- 3 -n_sites <- 20 - -# n_sites x n_env matrix of environmental variables -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites) -# n_sites observations of species presence or absence -occupancy <- rbinom(n_sites, 1, 0.5) - -## ----logistic_greta----------------------------------------------------------- -alpha <- normal(0, 10) -beta <- normal(0, 10, dim = n_env) - -# logit-linear model -linear_predictor <- alpha + env %*% beta -p <- ilogit(linear_predictor) - -# distribution (likelihood) over observed values -distribution(occupancy) <- bernoulli(p) - -## ----data_poisson, highlight = FALSE------------------------------------------ -# make fake data -n_env <- 3 -n_sites <- 20 - -# n_sites x n_env matrix of environmental variables -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites) -# n_sites observations of species abundance -occupancy <- rpois(n_sites, 5) - -## ----poisson_greta------------------------------------------------------------ -alpha <- normal(0, 10) -beta <- normal(0, 10, dim = n_env) -linear_predictor <- alpha + env %*% beta -lambda <- exp(linear_predictor) -distribution(occupancy) <- poisson(lambda) - -## ----data_logistic_error_term_greta, highlight = FALSE------------------------ -# make fake data -n_env <- 3 -n_sites <- 20 -n_obs <- 5 - -# n_sites x n_env matrix of environmental variables -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites) -# n_sites observations of species presence or absence over n_obs visits -occupancy <- rbinom(n_sites, n_obs, 0.5) - -## ----logistic_error_term_greta------------------------------------------------ -alpha <- normal(0, 10) -beta <- normal(0, 10, dim = n_env) -error <- normal(0, 10, dim = n_sites) - -# logit-linear model with extra variation -linear_predictor <- alpha + env %*% beta + error -p <- ilogit(linear_predictor) - -# distribution (likelihood) over observed values -distribution(occupancy) <- binomial(n_obs, p) - -## ----data_multispecies_bernoulli, highlight = FALSE--------------------------- -# make fake data -n_species <- 5 -n_env <- 3 -n_sites <- 20 - -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites) -occupancy <- matrix(rbinom(n_species * n_sites, 1, 0.5), nrow = n_sites) - -## ----multispecies_bernoulli_greta--------------------------------------------- -alpha <- normal(0, 10, dim = n_species) -beta <- normal(0, 10, dim = c(n_env, n_species)) - -env_effect <- env %*% beta - -# add intercepts for all species -linear_predictor <- sweep(env_effect, 2, alpha, FUN = '+') - -# ilogit of linear predictor -p <- ilogit(linear_predictor) - -# a single observation means our data are bernoulli distributed -distribution(occupancy) <- bernoulli(p) - -## ----data_multispecies_partially_pool, highlight = FALSE---------------------- -# make fake data -n_species <- 5 -n_env <- 1 -n_sites <- 50 - -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites) -occupancy <- matrix(rbinom(n_sites * n_species, 1, 0.5), nrow = n_sites) - -## ----multispecies_partially_pool_greta---------------------------------------- -global_alpha <- normal(0, 10, dim = 1) -global_alpha_sd <- uniform(0, 10, dim = 1) -alpha <- normal(global_alpha, global_alpha_sd, dim = n_species) - -global_betas <- normal(0, 10, dim = n_env) -global_betas_sd <- uniform(0, 10, dim = n_env) -beta <- normal(global_betas, global_betas_sd, dim = c(n_env, n_species)) - -env_effect <- env %*% beta - -# add intercepts for all species -linear_predictor <- sweep(env_effect, 2, alpha, FUN = '+') - -# ilogit of linear predictor -p <- ilogit(linear_predictor) - -distribution(occupancy) <- bernoulli(p) - -## ----data_multilevel, highlight = FALSE--------------------------------------- -# make fake data -n_species <- 3 -n_env <- 1 -n_sites <- 5 -n_traits <- 1 - -# n_sites x n_env matrix of environmental variables -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites) -# n_species * n_traits matix of trait variables -traits <- matrix(rnorm(n_species * n_traits), nrow = n_species) -# n_sites * n_species matrix of observed occupancy -occupancy <- matrix(rbinom(n_sites * n_species, 1, 0.5), nrow = n_sites) - -## ----multilevel_greta--------------------------------------------------------- -# include a column of 1's for intercept estimation in the sub-model (traits) and base model -traits <- cbind(rep(1, n_species), traits) -env <- cbind(rep(1, n_sites), env) - -# redefine n_env and n_traits after adding columns for intercepts -n_env <- ncol(env) -n_traits <- ncol(traits) - -# sub-model parameters have normal prior distributions -g <- normal(0, 10, dim = c(n_env, n_traits)) -# parameters of the base model are a function of the parameters of the sub-model -beta <- g %*% t(traits) - -# use the coefficients to get the model linear predictor -linear_predictor <- env %*% beta - -# use the logit link to get probabilities of occupancy -p <- ilogit(linear_predictor) - -# data are bernoulli distributed -distribution(occupancy) <- bernoulli(p) - -## ----cjs_data, highlight = FALSE---------------------------------------------- -n_obs <- 100 -n_time <- 20 -y <- matrix(sample(c(0, 1), size = (n_obs * n_time), replace = TRUE), - ncol = n_time) - -## ----cjs_greta---------------------------------------------------------------- -# data summaries -first_obs <- apply(y, 1, function(x) min(which(x > 0))) -final_obs <- apply(y, 1, function(x) max(which(x > 0))) -obs_id <- apply(y, 1, function(x) seq(min(which(x > 0)), max(which(x > 0)), by = 1)[-1]) -obs_id <- unlist(obs_id) -capture_vec <- apply(y, 1, function(x) x[min(which(x > 0)):max(which(x > 0))][-1]) -capture_vec <- unlist(capture_vec) - -# priors -phi <- beta(1, 1, dim = n_time) -p <- beta(1, 1, dim = n_time) - -# derived parameter -chi <- ones(n_time) -for (i in seq_len(n_time - 1)) { - tn <- n_time - i - chi[tn] <- (1 - phi[tn]) + phi[tn] * (1 - p[tn + 1]) * chi[tn + 1] -} - -# dummy variables -alive_data <- ones(length(obs_id)) # definitely alive -not_seen_last <- final_obs != 20 # ignore observations in last timestep -final_observation <- ones(sum(not_seen_last)) # final observation - -# set likelihoods -distribution(alive_data) <- bernoulli(phi[obs_id - 1]) -distribution(capture_vec) <- bernoulli(p[obs_id]) -distribution(final_observation) <- bernoulli(chi[final_obs[not_seen_last]]) - -## ----cjs_stan, echo = FALSE--------------------------------------------------- -cat(readLines('https://raw.githubusercontent.com/stan-dev/example-models/master/misc/ecology/mark-recapture/cjs-K.stan'), sep = '\n') - diff --git a/revdep/library.noindex/greta/old/greta/doc/example_models.html b/revdep/library.noindex/greta/old/greta/doc/example_models.html index 66c7d79e..9d2171f0 100644 --- a/revdep/library.noindex/greta/old/greta/doc/example_models.html +++ b/revdep/library.noindex/greta/old/greta/doc/example_models.html @@ -29,111 +29,16 @@ +code{white-space: pre-wrap;} +span.smallcaps{font-variant: small-caps;} +span.underline{text-decoration: underline;} +div.column{display: inline-block; vertical-align: top; width: 50%;} +div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} +ul.task-list{list-style: none;} + - - - @@ -339,435 +244,32 @@

    Common models

    Below are a few examples of common statistical models implemented in greta.


    -
    -

    Linear regression

    -

    A simple, one-variable Bayesian linear regression model using the -attitude data

    -
    # variables & priors
    -int <- normal(0, 10)
    -coef <- normal(0, 10)
    -sd <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -# linear predictor
    -mu <- int + coef * attitude$complaints
    -
    -# observation model
    -distribution(attitude$rating) <- normal(mu, sd)

    -
    -
    -

    Multiple linear regression

    -

    A multi-variable Bayesian linear regression model using the attitude -data

    -
    data(attitude)
    -design <- as.matrix(attitude[, 2:7])
    -
    int <- normal(0, 10)
    -coefs <- normal(0, 10, dim = ncol(design))
    -sd <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -# matrix multiplication is more efficient than multiplying the coefficients
    -# separately
    -mu <- int + design %*% coefs
    -
    -distribution(attitude$rating) <- normal(mu, sd)

    -
    -
    -

    Multiple Poisson regression

    -

    A multiple Bayesian linear regression model using the -warpbreaks data.

    -
    data("warpbreaks")
    -X <- as_data(model.matrix(breaks ~ wool + tension, warpbreaks))
    -y <- as_data(warpbreaks$breaks)
    -
    int <- variable()
    -coefs <- normal(0, 5, dim = ncol(X) - 1)
    -beta <- c(int, coefs)
    -
    -eta <- X %*% beta
    -
    -distribution(y) <- poisson(exp(eta))

    -
    -
    -

    Multiple categorical regression

    -

    A multi-variable Bayesian categorical regression model using the iris -data.

    -
    data(iris)
    -X <- as_data(cbind(1, iris[, 1:4]))
    -y <- model.matrix(~ Species - 1, iris)
    -P <- ncol(X)
    -K <- ncol(y)
    -
    beta <- normal(0, 5, dim = c(P, K - 1))
    -eta <- X %*% beta
    -prob <- imultilogit(eta)
    -distribution(y) <- categorical(prob)

    -
    -
    -

    Multiple linear regression with LASSO prior

    -

    A multi-variable Bayesian linear regression model using an -exponential-normal prior for the coefficients.

    -
    data(attitude)
    -design <- as.matrix(attitude[, 2:7])
    -
    int <- normal(0, 10)
    -sd <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -tau <- exponential(0.5, dim = ncol(design)) 
    -coefs <- normal(0, tau)
    -mu <- int + design %*% coefs
    -
    -distribution(attitude$rating) <- normal(mu, sd)

    -
    -
    -

    Hierarchical linear regression

    -

    A hierarchical, Bayesian linear regression model using the iris data, -with random intercepts for each of the three species.

    -
    # linear model parameters
    -int <- normal(0, 10)
    -coef <- normal(0, 10)
    -sd <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -# hierarchical model for species effect; use the first species as the baseline
    -# like in lm()
    -species_sd <- lognormal(0, 1)
    -species_offset <- normal(0, species_sd, dim = 2)
    -species_effect <- rbind(0, species_offset)
    -species_id <- as.numeric(iris$Species)
    -
    -# model
    -mu <- int + coef * iris$Sepal.Width + species_effect[species_id]
    -distribution(iris$Sepal.Length) <- normal(mu, sd)

    -
    -
    -

    Random intercept-slope model

    -

    A hierarchical, Bayesian linear regression model using the iris data, -with random intercepts and slopes for each of the three species. The -slopes and intercepts for each species are uncorrelated in this -example.

    -
    # linear model parameters
    -int <- normal(0, 10)
    -coef <- normal(0, 10)
    -sd <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -species_id <- as.numeric(iris$Species)
    -
    -# random intercepts
    -species_int_sd <- lognormal(0, 1)
    -species_int <- normal(0, species_int_sd, dim = 2)
    -species_int_eff <- rbind(0, species_int)
    -
    -# random slopes
    -species_slope_sd <- lognormal(0, 1)
    -species_slope <- normal(0, species_slope_sd, dim = 2)
    -species_slope_eff <- rbind(0, species_slope)
    -
    -# model
    -mu <- int + coef * iris$Sepal.Width + species_int_eff[species_id] + iris$Sepal.Width * species_slope_eff[species_id]
    -distribution(iris$Sepal.Length) <- normal(mu, sd)

    -
    -

    Random intercept-slope model (with correlated effects)

    -

    A hierarchical, Bayesian linear regression model using the iris data, -with random intercepts and slopes for each of the three species. The -slopes and intercepts for each species are correlated in this -example.

    -
    # model matrix
    -modmat <- model.matrix(~ Sepal.Width, iris) 
    -# index of species
    -jj <- as.numeric(iris$Species)
    -
    -M <- ncol(modmat) # number of varying coefficients
    -N <- max(jj) # number of species
    -
    -# prior on the standard deviation of the varying coefficient
    -tau <- exponential(0.5, dim = M)
    -
    -# prior on the correlation between the varying coefficient
    -Omega <- lkj_correlation(3, M)
    -
    -# optimization of the varying coefficient sampling through
    -# cholesky factorization and whitening
    -Omega_U <- chol(Omega)
    -Sigma_U <- sweep(Omega_U, 2, tau, "*")
    -z <- normal(0, 1, dim = c(N, M)) 
    -ab <- z %*% Sigma_U # equivalent to: ab ~ multi_normal(0, Sigma_U)
    -
    -# the linear predictor
    -mu <- rowSums(ab[jj,] * modmat)
    -
    -# the residual variance
    -sigma_e <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -#model
    -y <- iris$Sepal.Length
    -distribution(y) <- normal(mu, sigma_e)
    -
    -

    Common Bayesian priors

    The following examples show some common Bayesian priors of which some induce sparsity.


    -
    -

    Improper flat prior

    -

    A simple, one-variable Bayesian linear regression model that uses -flat priors for the coefficients. A flat prior using -variable puts an unbounded uniform distribution on the -parameter. With unconstrained flat priors, the posterior will be -proportional to the likelihood and the MAP will correspond to the MLE. -Flat priors are usually chosen when there is little knowledge about the -parameters available.

    -
    # variables & priors
    -int  <- variable()
    -coef <- variable()
    -sd   <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -# linear predictor
    -mu <- int + coef * attitude$complaints
    -
    -# observation model
    -distribution(attitude$rating) <- normal(mu, sd)

    -
    -
    -

    Ridge prior

    -

    Here we estimate a simple, one-variable Bayesian linear regression -model that uses a ridge prior. The ridge prior has a -frequentist interpretation where it is used as a penalty for regression -coefficients. Among other effects, the penalty shrinks the coefficients -towards zero to reduce variance without setting them to zero. The -Bayesian version uses a normal distribution for the slopes and a inverse -gamma prior for the strength of the penalty. Note that since the prior -in our intercept is still improper, the joint prior is also -improper.

    -
    # variables & priors
    -int <- variable()
    -sd <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -tau <- inverse_gamma(1, 1)
    -coef <- normal(0, tau)
    -
    -# linear predictor
    -mu <- int + coef * attitude$complaints
    -
    -# observation model
    -distribution(attitude$rating) <- normal(mu, sd)

    -
    -
    -

    Exponential-normal prior

    -

    In this example we infer the parameters of one-variable Bayesian -linear regression model using an exponential-normal prior. A compound -exponential-normal prior can be interpreted like an equivalent to the -frequentist LASSO. The exponential-normal prior yields a posterior that -is pooled towards zero. An exponential-normal prior, or equivalently a -Laplace prior, is consequently often chosen when a sparse solution is -assumed, which, for instance, is a natural scenario in many biological -settings.

    -
    # variables & priors
    -int <- variable()
    -sd <- inverse_gamma(1, 1)
    -
    -lambda <- gamma(1, 1)
    -tau <- exponential(0.5 * lambda**2)
    -coef <- normal(0, tau)
    -
    -# linear predictor
    -mu <- int + coef * attitude$complaints
    -
    -# observation model
    -distribution(attitude$rating) <- normal(mu, sd)

    -
    -
    -

    Horseshoe prior

    -

    A simple, one-variable Bayesian linear regression model using a -horseshoe prior. The horseshoe, just as the LASSO, can be used when the -slopes are assumed to be sparse. According to the original publication: -> its flat, Cauchy-like tails allow strong signals to remain large -[…] > a posteriori. Yet its infinitely tall spike at the origin -provides > severe shrinkage for the zero elements

    -
    horseshoe <- function (tau = 1, dim = NULL) {
    -  lambda <- cauchy(0, 1, truncation = c(0, Inf), dim = dim)
    -  sd <- tau ^ 2 * lambda ^ 2
    -  normal(0, sd, dim = dim)
    -}
    -
    -# variables & priors
    -int <- variable()
    -sd <- inverse_gamma(1, 1)
    -coef <- horseshoe()
    -
    -# linear predictor
    -mu <- int + coef * attitude$complaints
    -
    -# observation model
    -distribution(attitude$rating) <- normal(mu, sd)

    -
    -

    Regularized horseshoe prior

    -

    The regularized (‘Finnish’) horseshoe (doi.org/10.1214/17-EJS1337SI) -remedies a problem of the original horseshoe: large, unregularized -values for the coefficients. This is especially problematic in scenarios -where the parameters are only weakly identified by the data, as in -logistic regression with perfectly seperable data.

    -
    regularized_horseshoe <- function (tau = 1,  c = 1, dim = NULL) {
    -  stopifnot(c > 0)
    -  lambda <- cauchy(0, 1, truncation = c(0, Inf), dim = dim)
    -  lambda_tilde <- (c^2 * lambda^2) / (c^2 + tau^2 * lambda^2)
    -  sd <- tau ^ 2 * lambda_tilde ^ 2
    -  normal(0, sd, dim = dim)
    -}
    -
    -# variables & priors
    -int <- variable()
    -sd <- inverse_gamma(1, 1)
    -coef <- regularized_horseshoe()
    -
    -# linear predictor
    -mu <- int + coef * attitude$complaints
    -
    -# observation model
    -distribution(attitude$rating) <- normal(mu, sd)
    -
    -

    Advanced Bayesian models

    Below are some more advanced examples implemented in greta.


    -
    -

    Hierarchical linear regression in general conditional -formulation

    -

    A hierarchical, Bayesian linear regression model using the iris data, -with random intercepts and slopes for each of the three species. The -slopes and intercepts for each species are correlated in this -example. We allow every species to have a species specific slope for -Sepal.Length.

    -
    int  <- normal(0, 10)
    -coef <- normal(0, 10)
    -sd   <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -n_species  <- length(unique(iris$Species))
    -species_id <- as.numeric(iris$Species)
    -
    -Z <- model.matrix(~ Species + Sepal.Length * Species - 1, data = iris)
    -
    -gamma_matrix <- multivariate_normal(matrix(0, 1, 2),
    -                                    diag(2),
    -                                    n_realisations = 3) 
    -gamma <- c(gamma_matrix)
    -
    -wi <- as_data(iris$Sepal.Width)
    -Z  <- as_data(Z)
    -mu <- int + coef * wi + Z %*% gamma
    -
    -distribution(iris$Sepal.Length) <- normal(mu, sd)

    -
    -
    -

    Hierarchical linear regression in general marginal formulation

    -

    A hierarchical, Bayesian linear regression model using the iris data, -with random intercepts and slopes for each of the three species. This -time we try to set up the marginal model, i.e. when we -integrate the conditional density.

    -
    int  <- variable()
    -coef <- normal(0, 5)
    -sd   <- cauchy(0, 3, truncation = c(0, Inf))
    -
    -n_species  <- length(unique(iris$Species))
    -species_id <- as.numeric(iris$Species)
    -
    -Z <- model.matrix(~ Species + Sepal.Length * Species - 1, data = iris)
    -G  <- zeros(n_species * 2, n_species * 2)
    -
    -for (s in unique(species_id)) {
    -  G[c(s, s + n_species), c(s, s + n_species)] <- diag(2)
    -}
    -
    -mu <- int + coef * iris$Sepal.Width
    -V <- zeros(nrow(iris), nrow(iris))
    -diag(V) <- sd
    -
    -Z <- as_data(Z)
    -V <- V + Z %*% G %*% t(Z)
    -
    -sep <- t(iris$Sepal.Width)
    -distribution(sep) <- multivariate_normal(t(mu), V)

    -
    -
    -

    Bayesian neural network

    -

    Bayesian neural network estimates an easy neural network -with a normal prior on the edge weights. For clarity we use an -architecture without a hidden layer, such that the weights actually -correspond to coefficients in a linear regression model.

    -
    N <- 100
    -p <- 10
    -
    -set.seed(23)  
    -X <- matrix(rnorm(N * p), N)
    -beta <- rnorm(10)
    -y <- X %*% beta + rnorm(N, sd = 0.1)
    -
    neural_network <- function(x)
    -{
    -  # this can be arbitrarily complex, e.g. multiple hidden layers
    -  x %*% weights
    -}
    -  
    -weights <- normal(0, 1, dim = c(p, 1))
    -sd <- inverse_gamma(1, 1)
    -
    -distribution(y) <- normal(neural_network(X), sd)

    -
    -

    Factor analysis

    -

    Factor analysis is a linear latent model used for finding a -lower-dimensional probabilistic description of a data set with -observations \(\mathbf{x}_i \in -\mathbb{R}^p\). We assume the data are generated according to -\[ -\mathbf{x}_i = \mathbf{W} \mathbf{z}_i + \boldsymbol \mu + \epsilon_i -\] where the noise \(\epsilon\) -is normally distributed with zero mean and diagonal covariance matrix -\(\Psi = \mathrm{diag}(\psi_1, \dots, -\psi_p)\). The goal of factor analysis is to estimate the latent -variables \(\mathbf{z}_i -\mathbb{R}^q\).

    -

    In this example we take the mean vector \(\boldsymbol \mu\) to be zero.

    -
    -
    generate.data <- function(n = 100, p = 5, q = 2, psi = diag(rgamma(p, 1, 1)))
    -{
    -  W  <- matrix(rnorm(p * q, 1), p, q)
    -  Z  <- matrix(rnorm(q * n, 2), q, n)
    -  WZ <- W %*% Z
    -  
    -  X  <- matrix(0, n, p)
    -  for (i in seq_len(n)) {
    -    X[i, ] <- MASS::mvrnorm(1, WZ[, i], psi)
    -  }
    -  
    -  list(X = X, W = W, Z = Z, psi = psi)
    -}
    -
    -n <- 100
    -p <- 5
    -q <- 2
    -data <- generate.data(n = n, p = p, q = q)
    -X <- data$X
    -
    -
    W <- normal(0, 1, dim = c(p, q))
    -Z <- normal(0, 1, dim = c(q, n))
    -psi <- zeros(p, p)
    -diag(psi) <- inverse_gamma(1, 1, dim = p)
    -
    -distribution(X) <- multivariate_normal(t(W %*% Z), psi)
    -
    -

    BUGS models

    The BUGS project provide a number of example models written in the @@ -775,273 +277,20 @@

    BUGS models

    and likely also in JAGS. The Stan wiki provides Stan implementations of these models.

    The following sections provide greta implementations of some of these -example models, alongside the BUGS code from WinBUGS +example models, alongside the BUGS code from WinBUGS examples volume 2 (pdf) and Stan code and an R version of the data from the Stan example models wiki.


    -
    -

    Air

    -

    Air analyses reported respiratory illness versus exposure to -nitrogen dioxide in 103 children. The parameters alpha, -beta and sigma2 are known in advance, and the -data are grouped into three categories.

    -

    See WinBUGS -examples volume 2 (pdf) for details.

    -
    -

    data

    -
    y <- c(21, 20, 15)
    -n <- c(48, 34, 21)
    -Z <- c(10, 30, 50)
    -alpha <- 4.48
    -beta <- 0.76
    -sigma2 <- 81.14
    -sigma <- sqrt(sigma2)
    -tau <- 1 / sigma2
    -J <- 3
    -
    -
    -

    greta code

    -
    theta <- normal(0, 32, dim = 2)
    -mu <- alpha + beta * Z
    -X <- normal(mu, sigma)
    -p <- ilogit(theta[1] + theta[2] * X)
    -distribution(y) <- binomial(n, p)
    -
    -
    -

    BUGS/JAGS code

    -
    -
    for(j in 1 : J) {
    -   y[j] ~ dbin(p[j], n[j])
    -   logit(p[j]) <- theta[1] + theta[2] * X[j]
    -   X[j] ~ dnorm(mu[j], tau)
    -   mu[j] <- alpha + beta * Z[j]
    -}
    -theta[1] ~ dnorm(0.0, 0.001)
    -theta[2] ~ dnorm(0.0, 0.001)
    -
    -
    -
    -

    Stan code

    -
    -
    data {
    -  real alpha;
    -  real beta;
    -  real<lower=0> sigma2;
    -  int<lower=0> J;
    -  array[J] int y;
    -  vector[J] Z;
    -  array[J] int n;
    -}
    -transformed data {
    -  real<lower=0> sigma;
    -  sigma = sqrt(sigma2);
    -}
    -parameters {
    -  real theta1;
    -  real theta2;
    -  vector[J] X;
    -}
    -model {
    -  array[J] real p;
    -  theta1 ~ normal(0, 32); // 32^2 = 1024 
    -  theta2 ~ normal(0, 32);
    -  X ~ normal(alpha + beta * Z, sigma);
    -  y ~ binomial_logit(n, theta1 + theta2 * X);
    -}
    -

    -
    -
    -

    Beetles

    -

    Beetles considers dose-response data from an experiment -applying carbon disulphide to 8 beetles. The original example compares -three different link functions; the logit, probit and complementary -log-log. Here, only the code for the logit link is shown. You can -implement the other two link functions in greta by changing -ilogit to iprobit or -icloglog.

    -

    See WinBUGS -examples volume 2 (pdf) for details.

    -
    -

    data

    -
    x <- c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610, 1.8839)
    -n <- c(59, 60, 62, 56, 63, 59, 62, 60)
    -r <- c(6, 13, 18, 28, 52, 53, 61, 60)
    -N <- 8
    -
    -
    -

    greta code

    -
    alpha_star <- normal(0, 32)
    -beta <- normal(0, 32)
    -p <- ilogit(alpha_star + beta * (x - mean(x)))
    -distribution(r) <- binomial(n, p)
    -
    -alpha <- alpha_star - beta * mean(x)
    -rhat <- p * n
    -
    -
    -

    BUGS/JAGS code

    -
    -
    for( i in 1 : N ) {
    -  r[i] ~ dbin(p[i],n[i])
    -  logit(p[i]) <- alpha.star + beta * (x[i] - mean(x[]))
    -  rhat[i] <- n[i] * p[i]
    -  culmative.r[i] <- culmative(r[i], r[i])
    -}
    -alpha <- alpha.star - beta * mean(x[])
    -beta ~ dnorm(0.0,0.001)
    -alpha.star ~ dnorm(0.0,0.001)
    -
    -
    -
    -

    Stan code

    -
    -
    data {
    -  int<lower=0> N;
    -  array[N] int<lower=0> n;
    -  array[N] int<lower=0> r;
    -  vector[N] x;
    -}
    -transformed data {
    -  vector[N] centered_x;
    -  real mean_x;
    -  mean_x = mean(x);
    -  centered_x = x - mean_x;
    -}
    -parameters {
    -  real alpha_star;
    -  real beta;
    -}
    -transformed parameters {
    -  vector[N] m;
    -  m = alpha_star + beta * centered_x;
    -}
    -model {
    -  alpha_star ~ normal(0.0, 1.0E4);
    -  beta ~ normal(0.0, 1.0E4);
    -  r ~ binomial_logit(n, m);
    -}
    -generated quantities {
    -  real alpha;
    -  array[N] real p;
    -  array[N] real llike;
    -  array[N] real rhat;
    -  for (i in 1 : N) {
    -    p[i] = inv_logit(m[i]);
    -    llike[i] = r[i] * log(p[i]) + (n[i] - r[i]) * log(1 - p[i]);
    -    rhat[i] = p[i] * n[i]; // fitted values
    -  }
    -  alpha = alpha_star - beta * mean_x;
    -}
    -
    -
    -
    -

    Stan models

    The following few code examples show how Stan code can be translated in equivalent greta models.


    -
    -

    Lightspeed

    -

    Lightspeed estimates a linear normal model without -predictors. The data are 66 measurements from Simon Newcomb and -represent the time required for light to travel roughly 7500 meters.

    -

    See also the Stan -examples for details.

    -
    -

    data

    -
    y <- c(28, 26, 33, 24, 34, -44, 27, 16, 40, -2, 29, 22, 24, 21, 25, 
    -       30, 23, 29, 31, 19, 24, 20, 36, 32, 36, 28, 25, 21, 28, 29, 
    -       37, 25, 28, 26, 30, 32, 36, 26, 30, 22, 36, 23, 27, 27, 28, 
    -       27, 31, 27, 26, 33, 26, 32, 32, 24, 39, 28, 24, 25, 32, 25, 
    -       29, 27, 28, 29, 16, 23)
    -n <- length(y)
    -
    -
    -

    greta code

    -
    beta  <- variable()
    -sigma <- variable(lower = 0)
    -
    -distribution(y) <- normal(beta, sigma)
    -
    -
    -

    Stan code

    -
    -
    data {
    -  int<lower=0> N;
    -  vector[N] y;
    -}
    -parameters {
    -  vector[1] beta;
    -  real<lower=0> sigma;
    -}
    -model {
    -  y ~ normal(beta[1], sigma);
    -}
    -

    -
    -
    -

    Eight schools

    -

    Eight schools estimates the effect of coaching programs in -eight schools. The data are 8 measurements of coaching effects along -with their standard errors.

    -

    See also the Stan -example for details.

    -
    -

    data

    -
    y <- c(28,  8, -3,  7, -1,  1, 18, 12)
    -sigma_y <- c(15, 10, 16, 11,  9, 11, 10, 18)
    -N  <- length(y)
    -
    -
    -

    greta code

    -
    sigma_eta <- inverse_gamma(1, 1)
    -eta <- normal(0, sigma_eta, dim=N)
    -
    -mu_theta <- normal(0, 100)
    -xi <- normal(0, 5)
    -theta <- mu_theta + xi * eta
    -
    -distribution(y) <- normal(theta, sigma_y)
    -
    -
    -

    Stan code

    -
    -
    data {
    -  int<lower=0> N;
    -  vector[N] y;
    -  vector[N] sigma_y;
    -}
    -parameters {
    -  vector[N] eta;
    -  real mu_theta;
    -  real<lower=0, upper=100> sigma_eta;
    -  real xi;
    -}
    -transformed parameters {
    -  real<lower=0> sigma_theta;
    -  vector[N] theta;
    -  
    -  theta = mu_theta + xi * eta;
    -  sigma_theta = fabs(xi) / sigma_eta;
    -}
    -model {
    -  mu_theta ~ normal(0, 100);
    -  sigma_eta ~ inv_gamma(1, 1); //prior distribution can be changed to uniform
    -  
    -  eta ~ normal(0, sigma_eta);
    -  xi ~ normal(0, 5);
    -  y ~ normal(theta, sigma_y);
    -}
    -
    -
    -
    -

    Ecological models

    Here we provide some examples of common ecological models. We begin @@ -1052,404 +301,14 @@

    Ecological models

    multiple species: independently but concurrently modelled species, partially pooled coefficients, repeated measures, and sub-models.


    -
    -

    Logistic regression

    -

    A simple logistic regression being to estimate the probability of -species presence along a number of environmental gradients.

    -
    -

    data

    -
    # make fake data
    -n_env <- 3
    -n_sites <- 20
    -
    -# n_sites x n_env matrix of environmental variables
    -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites) 
    -# n_sites observations of species presence or absence
    -occupancy <- rbinom(n_sites, 1, 0.5) 
    -
    -
    -

    greta code

    -
    alpha <- normal(0, 10)
    -beta <- normal(0, 10, dim = n_env)
    -
    -# logit-linear model
    -linear_predictor <- alpha + env %*% beta
    -p <- ilogit(linear_predictor)
    -
    -# distribution (likelihood) over observed values
    -distribution(occupancy) <- bernoulli(p)

    -
    -
    -
    -

    Poisson regression

    -

    An example of a simple poisson regression being used to estimate the -abundance of a species along a number of environmental gradients.

    -
    -

    data

    -
    # make fake data
    -n_env <- 3
    -n_sites <- 20
    -
    -# n_sites x n_env matrix of environmental variables
    -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites) 
    -# n_sites observations of species abundance
    -occupancy <- rpois(n_sites, 5) 
    -
    -
    -

    greta code

    -
    alpha <- normal(0, 10)
    -beta <- normal(0, 10, dim = n_env)
    -linear_predictor <- alpha + env %*% beta
    -lambda <- exp(linear_predictor)
    -distribution(occupancy) <- poisson(lambda)

    -
    -
    -
    -

    Logistic regression with error term

    -

    This is an example of a simple logistic regression with an extra -observation-level error term, to model over-dispersion or clustering in -occupancy data from multiple visits.

    -
    -

    data

    -
    # make fake data
    -n_env <- 3
    -n_sites <- 20
    -n_obs <- 5
    -
    -# n_sites x n_env matrix of environmental variables
    -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites) 
    -# n_sites observations of species presence or absence over n_obs visits
    -occupancy <- rbinom(n_sites, n_obs, 0.5)
    -
    -
    -

    greta code

    -
    alpha <- normal(0, 10)
    -beta <- normal(0, 10, dim = n_env)
    -error <- normal(0, 10, dim = n_sites)
    -
    -# logit-linear model with extra variation
    -linear_predictor <- alpha + env %*% beta + error
    -p <- ilogit(linear_predictor)
    -
    -# distribution (likelihood) over observed values
    -distribution(occupancy) <- binomial(n_obs, p)

    -
    -
    -
    -

    Multiple species modelling independently and concurrently

    -

    An example of a logistic regression being used to estimate the -probability of multiple species’ presences along a number of -environmental gradients. Although modelled concurrently, the random -variables for each species are independent. We first simulate some data -to model followed by the greta code.

    -

    Where a single observation per species and location would have a -bernoulli error distribution, multiple observations for each species and -location have a binomial distribution.

    -

    When modelling multiple species (or other grouping factor), we need -an extra step in constructing the linear predictor. In order to add -multiple greta arrays together for each species we -can use the sweep() function.

    -
    -

    data

    -
    # make fake data
    -n_species <- 5
    -n_env <- 3
    -n_sites <- 20
    -
    -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites)
    -occupancy <- matrix(rbinom(n_species * n_sites, 1, 0.5), nrow = n_sites)
    -
    -
    -

    greta code

    -
    alpha <- normal(0, 10, dim = n_species)
    -beta <- normal(0, 10, dim = c(n_env, n_species))
    -
    -env_effect <- env %*% beta
    -
    -# add intercepts for all species
    -linear_predictor <- sweep(env_effect, 2, alpha, FUN = '+')
    -
    -# ilogit of linear predictor
    -p <- ilogit(linear_predictor)
    -
    -# a single observation means our data are bernoulli distributed
    -distribution(occupancy) <- bernoulli(p)

    -
    -
    -
    -

    Multiple species with partial pooling of regression -coefficients

    -

    An example of a logistic regression being used to estimate the -probability of multiple species’ presences along a number of -environmental gradients. Instead of assuming independence of species -regression coefficients, we assume they are drawn from a shared -distribution. We partially pool species responses. This gives us not ony -the regression coefficients for each species but also a global average -coefficient and a measure of variation between species responses to -environmental gradients.

    -
    -

    data

    -
    # make fake data
    -n_species <- 5
    -n_env <- 1
    -n_sites <- 50
    -
    -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites)
    -occupancy <- matrix(rbinom(n_sites * n_species, 1, 0.5), nrow = n_sites)
    -
    -
    -

    greta code

    -
    global_alpha <- normal(0, 10, dim = 1)
    -global_alpha_sd <- uniform(0, 10, dim = 1) 
    -alpha <- normal(global_alpha, global_alpha_sd, dim = n_species)
    -
    -global_betas <- normal(0, 10, dim = n_env)
    -global_betas_sd <- uniform(0, 10, dim = n_env)
    -beta <- normal(global_betas, global_betas_sd, dim = c(n_env, n_species))
    -
    -env_effect <- env %*% beta
    -
    -# add intercepts for all species
    -linear_predictor <- sweep(env_effect, 2, alpha, FUN = '+')
    -
    -# ilogit of linear predictor
    -p <- ilogit(linear_predictor)
    -
    -distribution(occupancy) <- bernoulli(p)

    -
    -
    -
    -

    Multiple species with sub-model for regression coefficients

    -

    An example of a logistic regression being used to estimate the -probability of multiple species’ presences along a number of -environmental gradients. Instead of assuming independence of species -regression coefficients, or partial pooling in shared distributions, we -use a sub-model to estimate species regression coefficients. In this -case, we’re using species traits to estimate their response to different -environmental gradients.

    -

    Because we’re building a sub-model, it’s more efficient to simply add -a column of ones to dataframes for the base model and sub-model. This is -simply to prevent our code from becoming too cumbersome. If we didn’t -want to use our sub-model to estimate the intercept, we would not need -to include the column of ones in the environmental dataframe.

    -
    -

    data

    -
    # make fake data
    -n_species <- 3
    -n_env <- 1
    -n_sites <- 5
    -n_traits <- 1
    -
    -# n_sites x n_env matrix of environmental variables
    -env <- matrix(rnorm(n_sites * n_env), nrow = n_sites)
    -# n_species * n_traits matix of trait variables
    -traits <- matrix(rnorm(n_species * n_traits), nrow = n_species)
    -# n_sites * n_species matrix of observed occupancy
    -occupancy <- matrix(rbinom(n_sites * n_species, 1, 0.5), nrow = n_sites)
    -
    -
    -

    greta code

    -
    # include a column of 1's for intercept estimation in the sub-model (traits) and base model
    -traits <- cbind(rep(1, n_species), traits)
    -env <- cbind(rep(1, n_sites), env)
    -
    -# redefine n_env and n_traits after adding columns for intercepts
    -n_env <- ncol(env)
    -n_traits <- ncol(traits)
    -
    -# sub-model parameters have normal prior distributions
    -g <- normal(0, 10, dim = c(n_env, n_traits))
    -# parameters of the base model are a function of the parameters of the sub-model
    -beta <-  g %*% t(traits) 
    -
    -# use the coefficients to get the model linear predictor
    -linear_predictor <- env %*% beta 
    -
    -# use the logit link to get probabilities of occupancy
    -p <- ilogit(linear_predictor)
    -
    -# data are bernoulli distributed
    -distribution(occupancy) <- bernoulli(p)

    -
    -
    -
    -

    Cormack-Jolly-Seber model

    -

    Cormack-Jolly-Seber (CJS) models estimate probabilities of -survival and recapture from mark-recapture data. These models assume -that we can only ever see individuals that have been initially marked -and released or recaptured following release (i.e. individuals do not -exist until first observed). The two key parameters are survival, \(\phi\), and probability of recapture, \(p\). There is an additional derived -parameter, \(\chi\), which is the -probability that an individual is not recaptured following its final -capture. \(\chi\) marginalises over -multiple scenarios in which the individual is not observed either -because it has died or because it is alive but not detected.

    -

    The introductory -book to the program MARK has a lot of information on mark-recapture -models, including CJS models (starting in Ch. 1) and the broader class -of Jolly-Seber models (Ch. 12). There is also a section on -mark-recapture models in the Stan language -manual, which goes through the derivation of the parameter \(\chi\).

    -
    -

    data

    -
    -
    n_obs <- 100
    -n_time <- 20
    -y <- matrix(sample(c(0, 1), size = (n_obs * n_time), replace = TRUE),
    -            ncol = n_time)
    -
    -
    -
    -

    greta code

    -
    # data summaries
    -first_obs <- apply(y, 1, function(x) min(which(x > 0)))
    -final_obs <- apply(y, 1, function(x) max(which(x > 0)))
    -obs_id <- apply(y, 1, function(x) seq(min(which(x > 0)), max(which(x > 0)), by = 1)[-1])
    -obs_id <- unlist(obs_id)
    -capture_vec <- apply(y, 1, function(x) x[min(which(x > 0)):max(which(x > 0))][-1])
    -capture_vec <- unlist(capture_vec)
    -
    -# priors
    -phi <- beta(1, 1, dim = n_time)
    -p <- beta(1, 1, dim = n_time)
    -
    -# derived parameter
    -chi <- ones(n_time)
    -for (i in seq_len(n_time - 1)) {
    -  tn <- n_time - i
    -  chi[tn] <- (1 - phi[tn]) + phi[tn] * (1 - p[tn + 1]) * chi[tn + 1]
    -}
    -
    -# dummy variables
    -alive_data <- ones(length(obs_id))            # definitely alive
    -not_seen_last <- final_obs != 20              # ignore observations in last timestep
    -final_observation <- ones(sum(not_seen_last)) # final observation
    -
    -# set likelihoods
    -distribution(alive_data) <- bernoulli(phi[obs_id - 1])
    -distribution(capture_vec) <- bernoulli(p[obs_id])
    -distribution(final_observation) <- bernoulli(chi[final_obs[not_seen_last]])
    -
    -
    -

    BUGS/JAGS code

    -
    -
    model {
    -  # priors
    -  for (t in 1:(n_time - 1)) {
    -    phi[t] ~ dunif(0, 1)
    -    p[t] ~ dunif(0, 1)
    -  }
    -  # likelihood
    -  for (i in 1:n_obs) {
    -    z[i, first_obs[i]] <- 1   # state at first capture must be 1!
    -    for (t in (first_obs[i] + 1):n_time) {
    -      mu1[i, t] <- phi[t - 1] * z[i, t - 1] 
    -      z[i, t] ~ dbern(mu1[i, t])   # true state
    -      mu2[i, t] <- p[t - 1] * z[i, t]
    -      y[i, t] ~ dbern(mu2[i, t])      # observed state
    -    }
    -  }
    -}
    -
    -
    -
    -

    Stan code

    -
    -
    /**
    - * Cormack-Jolly-Seber Model
    - * 
    - * following section 1.2.1 of:
    - * http://www.maths.otago.ac.nz/home/resources/theses/PhD_Matthew_Schofield.pdf
    - *
    - */
    -data {
    -  int<lower=2> K; // capture events
    -  int<lower=0> I; // number of individuals
    -  array[I, K] int<lower=0, upper=1> X; // X[i,k]: individual i captured at k
    -}
    -transformed data {
    -  array[I] int<lower=0, upper=K + 1> first; // first[i]: ind i first capture
    -  array[I] int<lower=0, upper=K + 1> last; // last[i]:  ind i last capture
    -  array[K] int<lower=0, upper=I> n_captured; // n_capt[k]: num aptured at k
    -  
    -  first = rep_array(K + 1, I);
    -  last = rep_array(0, I);
    -  for (i in 1 : I) {
    -    for (k in 1 : K) {
    -      if (X[i, k] == 1) {
    -        if (k < first[i]) {
    -          first[i] = k;
    -        }
    -        if (k > last[i]) {
    -          last[i] = k;
    -        }
    -      }
    -    }
    -  }
    -  
    -  n_captured = rep_array(0, K);
    -  for (i in 1 : I) {
    -    for (k in 1 : K) {
    -      n_captured[k] = n_captured[k] + X[i, k];
    -    }
    -  }
    -}
    -parameters {
    -  vector<lower=0, upper=1>[K - 1] phi; // phi[k]: Pr[alive at k + 1 | alive at k]
    -  vector<lower=0, upper=1>[K] p; // p[k]: Pr[capture at k]
    -  
    -  // note:  p[1] not used in model and hence not identified
    -}
    -transformed parameters {
    -  vector<lower=0, upper=1>[K] chi; // chi[k]: Pr[no capture >  k | alive at k]
    -  {
    -    int k;
    -    chi[K] = 1.0;
    -    k = K - 1;
    -    while (k > 0) {
    -      chi[k] = (1 - phi[k]) + phi[k] * (1 - p[k + 1]) * chi[k + 1];
    -      k = k - 1;
    -    }
    -  }
    -}
    -model {
    -  for (i in 1 : I) {
    -    if (last[i] > 0) {
    -      for (k in (first[i] + 1) : last[i]) {
    -        target += log(phi[k - 1]); // i survived from k-1 to k
    -        if (X[i, k] == 1) {
    -          target += log(p[k]);
    -        } // i captured at k
    -        else {
    -          target += log1m(p[k]);
    -        } // i not captured at k
    -      }
    -      target += log(chi[last[i]]); // i not seen after last[i]
    -    }
    -  }
    -}
    -generated quantities {
    -  // phi[K-1] and p(K) not identified, but product is
    -  real beta;
    -  vector<lower=0>[K] pop_hat; // population
    -  
    -  beta = phi[K - 1] * p[K];
    -  
    -  for (k in 1 : K) {
    -    pop_hat[k] = n_captured[k] / p[k];
    -  }
    -}
    -

    -
    -
    diff --git a/revdep/library.noindex/greta/old/greta/doc/faq.R b/revdep/library.noindex/greta/old/greta/doc/faq.R index 7354da3e..6143e308 100644 --- a/revdep/library.noindex/greta/old/greta/doc/faq.R +++ b/revdep/library.noindex/greta/old/greta/doc/faq.R @@ -1,4 +1,4 @@ -## ---- include = FALSE--------------------------------------------------------- +## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", diff --git a/revdep/library.noindex/greta/old/greta/doc/faq.html b/revdep/library.noindex/greta/old/greta/doc/faq.html index 0d128a69..49e81d23 100644 --- a/revdep/library.noindex/greta/old/greta/doc/faq.html +++ b/revdep/library.noindex/greta/old/greta/doc/faq.html @@ -29,23 +29,23 @@ +code{white-space: pre-wrap;} +span.smallcaps{font-variant: small-caps;} +span.underline{text-decoration: underline;} +div.column{display: inline-block; vertical-align: top; width: 50%;} +div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} +ul.task-list{list-style: none;} + +code{white-space: pre-wrap;} +span.smallcaps{font-variant: small-caps;} +span.underline{text-decoration: underline;} +div.column{display: inline-block; vertical-align: top; width: 50%;} +div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} +ul.task-list{list-style: none;} +