Skip to content

Commit

Permalink
Merge branch 'develop' into new-ddmodels
Browse files Browse the repository at this point in the history
  • Loading branch information
rsetienne authored Nov 26, 2024
2 parents 91fa0c3 + 1c607a1 commit c7ca3d3
Show file tree
Hide file tree
Showing 27 changed files with 300 additions and 111 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
^\.Rproj\.user$
^README\.md
^\.github$
^_pkgdown\.yml$
^docs$
^pkgdown$
86 changes: 19 additions & 67 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
Expand All @@ -25,85 +25,37 @@ jobs:

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

if: "contains(github.event.head_commit.message, '[run ci]') || (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') || github.event.pull_request"

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

- name: Install libcurl4-openssl-dev
if: matrix.config.r == 'devel'
run: sudo apt install -qq libcurl4-openssl-dev

- uses: r-lib/actions/setup-pandoc@v1
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
remotes::install_cran("crayon")
if (.Platform$OS.type == "unix") remotes::install_cran("doMC")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Install covr and test coverage
if: matrix.config.r == 'devel'
run: |
remotes::install_cran("covr", dependencies = TRUE, upgrade = "always")
covr::codecov()
shell: Rscript {0}
extra-packages: any::rcmdcheck, doMC=?ignore
needs: check

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
49 changes: 49 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
release:
types: [published]
workflow_dispatch:

name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
folder: docs
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
pull_request:

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
if: "contains(github.event.head_commit.message, '[run ci]') || (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop')"

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ src/*.so
src/*.dll
src-i386
src-x64
docs
16 changes: 9 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Package: DDD
Type: Package
Title: Diversity-Dependent Diversification
Version: 5.2.0
Date: 2023-02-06
Version: 5.2.3
Date: 2024-11-26
Depends: R (>= 3.5.0)
SystemRequirements: C++14
Imports:
deSolve,
ape,
Expand All @@ -16,12 +15,13 @@ Imports:
SparseM,
Rcpp (>= 1.0.10)
LinkingTo:
Rcpp,
Rcpp (>= 1.0.10),
RcppEigen,
BH (>= 1.81.0-1)
Suggests:
testthat,
testit
testthat (>= 3.0.0),
testit,
igraph
Authors@R: c(
person(given = "Rampal S.",
family = "Etienne",
Expand Down Expand Up @@ -61,4 +61,6 @@ Description:
<DOI:10.1093/sysbio/syaa048>.
Also contains functions to simulate the diversity-dependent
process.
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Config/testthat/edition: 3
URL: https://rsetienne.github.io/DDD/
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export(td_sim)
export(transform_pars)
export(untransform_pars)
export(what_is_this_ddmodel)
import(Rcpp)
useDynLib(DDD)
7 changes: 7 additions & 0 deletions R/DDD-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @keywords internal
#' @import Rcpp
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
6 changes: 3 additions & 3 deletions R/dd_KI_sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,10 @@ tes = L2phylo(L[,1:4],dropextinct = T)
tas = L2phylo(L[,1:4],dropextinct = F)
tesS = NULL
tes2 = NULL
tasS = NULL
tas2 = NULL
graphics::par(mfrow = c(1,2))
graphics::par(mai=c(0,0.5,0.5,0))
graphics::par(mai = c(0,0.5,0.5,0))
graphics::plot(tes)
graphics::title('Reconstructed tree', cex.main = 0.7)
graphics::plot(tas)
Expand All @@ -332,8 +334,6 @@ if(length(linlistS) > 0)
phytools::plotSimmap(tes2,cols,lwd = 3,pts = F, mar = c(0.1,0.1,1,0.1))
graphics::title('Reconstructed tree', cex.main = 0.7)
}
tasS = NULL
tas2 = NULL
allS = which(L[,5] == 1)
if(length(allS) > 0)
{
Expand Down
8 changes: 4 additions & 4 deletions R/dd_loglik.R
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,11 @@ dd_integrate <- function(initprobs,tvec,rhs_func,pars,rtol,atol,method)
rhs_func_name <- 'no_name'
if (is.character(rhs_func)) {
rhs_func_name <- rhs_func
if(rhs_func_name != 'dd_loglik_rhs' & rhs_func_name != 'dd_loglik_bw_rhs')
{
#if(rhs_func_name != 'dd_loglik_rhs' & rhs_func_name != 'dd_loglik_bw_rhs')
#{
rhs_func = match.fun(rhs_func)
}
}
#}
#}
if(rhs_func_name == 'dd_loglik_rhs' || rhs_func_name == 'dd_loglik_bw_rhs')
{
parsvec = c(dd_loglik_rhs_precomp(pars,initprobs),pars[length(pars) - 1])
Expand Down
23 changes: 20 additions & 3 deletions R/dd_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ simplex = function(fun,trparsopt,optimpars,...)
#' 'subplex'
#' @param optimpars Parameters of the optimization: relative tolerance in
#' function arguments, relative tolerance in function value, absolute tolerance
#' in function arguments, and maximum number of iterations
#' in function arguments as well as the function value, and maximum number of iterations
#' @param num_cycles Number of cycles of the optimization. When set to Inf, the
#' optimization will be repeated until the result is, within the tolerance,
#' equal to the starting values, with a maximum of 10 cycles.
Expand Down Expand Up @@ -760,7 +760,9 @@ optimizer <- function(
trparsopt[trparsopt == 0.5] <- 0.5 - jitter
outnew <- suppressWarnings(subplex::subplex(par = trparsopt,
fn = minfun1,
control = list(abstol = optimpars[3],reltol = optimpars[1],maxit = optimpars[4]),
control = list(abstol = optimpars[3],
reltol = optimpars[1],
maxit = optimpars[4]),
fun = fun,
...))
outnew <- list(par = outnew$par, fvalues = -outnew$value, conv = outnew$convergence)
Expand All @@ -773,7 +775,7 @@ optimizer <- function(
outnew <- suppressWarnings(DEoptim::DEoptim(fn = minfun2,
lower = rep(0, length(trparsopt)),
upper = rep(1, length(trparsopt)),
control = list(reltol = optimpars[1],
control = list(reltol = optimpars[2],
strategy = 2,
steptol = 100,
trace = FALSE,
Expand All @@ -783,6 +785,21 @@ optimizer <- function(

...))$optim
outnew <- list(par = outnew$bestmem, fvalues = -outnew$bestval, conv = 0)
} else if(substr(optimmethod,1,7) == 'optim::')
{
minfun3 <- function(trparsopt, fun, ...)
{
return(-fun(trparsopt = trparsopt, ...))
}
outnew <- suppressWarnings(optim(par = trparsopt,
fn = minfun3,
method = substr(optimmethod,8,nchar(optimmethod)),
control = list(reltol = optimpars[2],
abstol = optimpars[3],
maxit = optimpars[4]),
fun = fun,
...))
outnew <- list(par = outnew$par, fvalues = -outnew$value, conv = outnew$convergence)
}
if(cy > 1 & (any(is.na(outnew$par)) | any(is.nan(outnew$par)) | is.na(outnew$fvalues) | is.nan(outnew$fvalues) | outnew$conv != 0))
{
Expand Down
Loading

0 comments on commit c7ca3d3

Please sign in to comment.