Skip to content

Commit

Permalink
Merge pull request #11 from miraisolutions/feature/address-macos-cran…
Browse files Browse the repository at this point in the history
…-checks

Address macos CRAN checks
  • Loading branch information
riccardoporreca authored Apr 7, 2020
2 parents cf4669f + 8aa7faa commit e7c1350
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 22 deletions.
42 changes: 36 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
language: r
cache: packages
warnings_are_errors: true

r:
- devel
- release
- oldrel

# TeXLive issues for osx images
# https://travis-ci.community/t/latex-error-file-inconsolata-sty-not-found-only-on-osx-when-building-r-package/3261/4

os:
- linux
# - osx

matrix:
# Vanilla macOS machine: remove preinstalled homebrew installation
disable_homebrew: true

jobs:
# exclude:
# # macOS binary packages not available for r-devel
# - r: devel
# os: osx
include:
- r: devel
- r: release
after_success:
- Rscript -e 'covr::codecov()'
os: osx
r_check_args: --no-manual
- r: oldrel
os: osx
r_check_args: --no-manual

# Code coverage
after_success:
- >-
if [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$TRAVIS_R_VERSION_STRING" = "release" ]; then
echo Code coverage...
Rscript -e 'covr::codecov(type = "all")'
else
echo Skip code coverage
fi
warnings_are_errors: true
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ VignetteBuilder:
Encoding: UTF-8
LazyData: true
NeedsCompilation: yes
RoxygenNote: 7.0.2
RoxygenNote: 7.1.0
Collate:
'LdFlags.R'
'RcppExports.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(TRNGjump)
export(TRNGkind)
export(TRNGseed)
export(TRNGsplit)
export(check_rTRNG_linking)
export(defaultKind)
export(lagfib2plus_19937_64)
export(lagfib2xor_19937_64)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Underlying TRNG C++ library upgraded to version 4.22 (#6). This mainly includes: Fixing numerical convergence problems in the inverse of the incomplete Beta function; Removing support for C++ language standards older than C++11.
- Documentation and examples updated to include enforcing the C++11 standard required by the updated TRNG C++ library.
- New function `check_rTRNG_linking()` allows checking whether C++ code using the TRNG library can be built and linked against rTRNG (#10).
- Package vignettes now use `check_rTRNG_linking()` to build C++ code using TRNG only on systems supporting it. This addresses the vignette re-building issues in the CRAN package checks on macOS (and Solaris), and is broadly documented in the package, including README and vignettes (#10).

# rTRNG 4.20-1

Expand Down
31 changes: 31 additions & 0 deletions R/LdFlags.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,34 @@ asBuildPath <- function(path) {
}
return(path)
}

sourceCpp_minimal_code <- '
// [[Rcpp::depends(rTRNG)]]
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
#include <trng/yarn2.hpp>
// [[Rcpp::export]]
void exampleCpp() {
trng::yarn2 rng;
}
'

#' Check rTRNG linking.
#'
#' Check whether C++ code using the TRNG library can be built and linked against
#' \pkg{rTRNG} on the current system.
#'
#' @inheritParams base::try
#'
#' @return A scalar logical with the result of the check. If \code{FALSE}, using
#' the TRNG library from C++ code sourced via \code{\link[Rcpp]{sourceCpp}} or
#' part of an \R package is not expected to work.
#'
#' @export
check_rTRNG_linking <- function(silent = FALSE) {
check <- try(
silent = silent,
Rcpp::sourceCpp(code = sourceCpp_minimal_code)
)
!inherits(check, "try-error")
}
7 changes: 7 additions & 0 deletions R/rTRNG-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
#' \code{importFrom(rTRNG, TRNG.Version)} in the NAMESPACE file, and
#' setting relevant linker flags (via \code{\link[rTRNG]{LdFlags}}) and
#' C++11 compilation (\code{CXX_STD = CXX11}) in Makevars[.win].
#' \item
#' Note that C++ code using the TRNG library (sourced via
#' \code{Rcpp::sourceCpp} or part of an \R package) might fail on certain
#' systems due to issues with building and linking against \pkg{rTRNG}.
#' This is typically the case for macOS, and can generally be checked
#' using
#' \code{\link[rTRNG]{check_rTRNG_linking}}.
#' }
#' }
#' See the package vignettes (\code{browseVignettes("rTRNG")}) for an overview
Expand Down
11 changes: 10 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ x_serial <- rnorm_trng(1e5L)
identical(x_serial, x_parallel)
```


### Use TRNG from standalone C++

The TRNG C++ library is made available by **rTRNG** to standalone C++ code
Expand Down Expand Up @@ -199,3 +198,13 @@ Creating an R package with C++ code using the TRNG library and headers through
- Makevars: `PKG_LIBS += $(shell ${R_HOME}/bin/Rscript -e "rTRNG::LdFlags()")`
- Makevars.win: `PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "rTRNG::LdFlags()")`

### Note about C++ code on macOS

C++ code using the TRNG library (sourced via `Rcpp::sourceCpp` or part of an R
package) might fail on certain systems due to issues with building and linking
against **rTRNG**. This is typically the case for **macOS**, and can generally
be checked by running

```{r check-linking, eval=FALSE}
rTRNG::check_rTRNG_linking()
```
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,14 @@ through **rTRNG** is achieved by
"rTRNG::LdFlags()")`
- Makevars.win: `PKG_LIBS += $(shell
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "rTRNG::LdFlags()")`

### Note about C++ code on macOS

C++ code using the TRNG library (sourced via `Rcpp::sourceCpp` or part
of an R package) might fail on certain systems due to issues with
building and linking against **rTRNG**. This is typically the case for
**macOS**, and can generally be checked by running

``` r
rTRNG::check_rTRNG_linking()
```
21 changes: 21 additions & 0 deletions man/check_rTRNG_linking.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions man/rTRNG-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-TRNG.Engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ test_that("$split errors for out-of-range subsequence indices", {
p <- 5L
if (!grepl("(lagfib|mt)", engineClass)) {
expect_error(
e$split(p, 0L), "invalid", # 1-base indexing
e$split(p, 0L), class = "std::invalid_argument", # 1-base indexing
info = .name(engineClass)
)
expect_error(
e$split(p, p + 1L), "invalid",
e$split(p, p + 1L), class = "std::invalid_argument",
info = .name(engineClass)
)
expect_error(
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-TRNG.Random.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ test_that("TRNGsplit errors for out-of-range subsequence indices", {
TRNGkind(KIND)
TRNGseed(SEED)
p <- 5L
expect_error(TRNGsplit(p, 0L), "invalid") # 1-base indexing
expect_error(TRNGsplit(p, p + 1L), "invalid")
expect_error(TRNGsplit(p, 0L), class = "std::invalid_argument") # 1-base indexing
expect_error(TRNGsplit(p, p + 1L), class = "std::invalid_argument")
expect_error(TRNGsplit(p, -1L), "negative")
expect_error(TRNGsplit(-1L, 1L), "negative")
})
19 changes: 11 additions & 8 deletions vignettes/mcMat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ vignette: >
```{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE)
options(digits = 5) # for kable
linking_ok <- rTRNG::check_rTRNG_linking()
```


```{r include=FALSE, cache=FALSE}
```{r code, include=FALSE, cache=FALSE}
source("utils/read_chunk_wrap.R", echo = FALSE, print.eval = FALSE)
read_chunk_wrap("code/mcMat.R")
Rcpp::sourceCpp("code/mcMat.cpp", verbose = FALSE, embeddedR = FALSE)
read_chunk_wrap("code/mcMat.cpp")
Rcpp::sourceCpp("code/mcMatParallel.cpp", verbose = FALSE, embeddedR = FALSE)
read_chunk_wrap("code/mcMatParallel.cpp")
if (linking_ok) {
Rcpp::sourceCpp("code/mcMat.cpp", verbose = FALSE, embeddedR = FALSE)
Rcpp::sourceCpp("code/mcMatParallel.cpp", verbose = FALSE, embeddedR = FALSE)
}
```

Consider the Monte Carlo simulation of a matrix of i.i.d. normal random
Expand Down Expand Up @@ -71,9 +74,9 @@ enforces the C++11 standard required by TRNG >= 4.22.
```
As seen above for the R case, consistency of the simulation obtained via
`mcSubMatRcpp` with the full sequential simulation is guaranteed.
```{r subMatExampleRcpp}
```{r subMatExampleRcpp, eval=linking_ok}
```
```{r, echo=FALSE}
```{r, echo=FALSE, eval=linking_ok}
knitr::kable(cbind.data.frame(M = M, S = S), row.names = TRUE)
```

Expand All @@ -88,12 +91,12 @@ Monte Carlo simulations in parallel, for any subset `subCols` of the variables.
```
The parallel nature of the `yarn2` generator ensures the parallel simulation is
playing fair, i.e. is consistent with the sequential simulation.
```{r fullMatExampleRcppParallel}
```{r fullMatExampleRcppParallel, eval=linking_ok}
```
Similarly, we can achieve a consistent parallel simulation of a subset of the
variables only.
```{r subMatExampleRcppParallel}
```{r subMatExampleRcppParallel, eval=linking_ok}
```
```{r, echo=FALSE}
```{r, echo=FALSE, eval=linking_ok}
knitr::kable(cbind.data.frame(M = M, Sp = Sp), row.names = TRUE)
```
17 changes: 15 additions & 2 deletions vignettes/rTRNG.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vignette: >

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE)
linking_ok <- rTRNG::check_rTRNG_linking()
```


Expand Down Expand Up @@ -105,7 +106,7 @@ easily be compiled, specifying the `Rcpp::depends` attribute that allows
`Rcpp::plugins(cpp11)` is needed to enforce the C++11 standard required by TRNG
>= 4.22.
```{Rcpp sourceCpp}
```{Rcpp sourceCpp, eval=linking_ok}
// [[Rcpp::depends(rTRNG)]]
// TRNG >= 4.22 requires C++11
// [[Rcpp::plugins(cpp11)]]
Expand All @@ -132,7 +133,7 @@ NumericVector exampleCpp() {
exampleCpp()
*/
```
```{r sourceCpp-R, echo=FALSE}
```{r sourceCpp-R, echo=FALSE, eval=linking_ok}
exampleCpp()
```

Expand All @@ -148,3 +149,15 @@ Creating an R package with C++ code using the TRNG library and headers through
- setting the relevant linker flags in Makevars[.win] via `rTRNG::LdFlags()`
- Makevars: `PKG_LIBS += $(shell ${R_HOME}/bin/Rscript -e "rTRNG::LdFlags()")`
- Makevars.win: `PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "rTRNG::LdFlags()")`


### Note about C++ code on macOS

C++ code using the TRNG library (sourced via `Rcpp::sourceCpp` or part of an R
package) might fail on certain systems due to issues with building and linking
against **rTRNG**. This is typically the case for **macOS**, and can generally
be checked by running

```{r check-linking, eval=FALSE}
rTRNG::check_rTRNG_linking()
```

0 comments on commit e7c1350

Please sign in to comment.