Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ makefile
^\.github
netdiffuseR\.Rcheck
^\.devcontainer$
^\.vscode$
^\.vscode$
^scripts$
75 changes: 26 additions & 49 deletions .github/workflows/r.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# 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:
- main
- master
branches: [main, master]
pull_request:
branches:
- main
- master
branches: [main, master]

name: R-CMD-check

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

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -22,62 +21,40 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', valgrind: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', valgrind: true, http-user-agent: '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@v4

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

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

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

- 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: Restore R package cache
if: runner.os != 'Windows'
uses: actions/cache@v4
- 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")
shell: Rscript {0}
extra-packages: any::rcmdcheck
needs: check

- name: Check
- uses: r-lib/actions/check-r-package@v2
if: ${{ matrix.config.valgrind != true }}
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check")
shell: Rscript {0}
with:
args: 'c("--no-manual", "--as-cran")'
upload-snapshots: false
upload-results: false
check-dir: '"check"'
error-on: '"error"'

- name: Setup valgrind
if: ${{ matrix.config.valgrind == true }}
Expand Down
89 changes: 89 additions & 0 deletions scripts/check-github-actions-local.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! But we need to ensure that scripts is in the .Rbuildignore. Can you check that?

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bash
#
# check-github-actions-local.sh - Simulate GitHub Actions checks locally
#
# This script replicates the GitHub Actions workflow locally using Docker
# to test changes before pushing to GitHub.
#
# Usage:
# ./scripts/check-github-actions-local.sh [ubuntu|macos|windows|all]
#
# Requirements:
# - Docker installed and running
# - Run from repository root

set -e
set -u

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

# Configuration
PLATFORM="${1:-ubuntu}"
PACKAGE_NAME=$(awk '/^Package:/ {print $2}' DESCRIPTION)
PACKAGE_VERSION=$(awk '/^Version:/ {print $2}' DESCRIPTION)

echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}GitHub Actions Local Check${NC}"
echo -e "${GREEN}========================================${NC}"
echo "Package: ${PACKAGE_NAME} ${PACKAGE_VERSION}"
echo "Platform: ${PLATFORM}"
echo ""

case "$PLATFORM" in
ubuntu|linux)
echo -e "${YELLOW}[1/3] Testing Ubuntu (r-release)...${NC}"

# Use R-hub Ubuntu container (simulates ubuntu-latest with R release)
docker run --rm \
-v "$(pwd):/workspace" \
-w /workspace \
ghcr.io/r-hub/containers/ubuntu-release:latest \
bash -c "
set -e
echo '>>> Installing system dependencies...'
apt-get update > /dev/null 2>&1
apt-get install -y libssl-dev libcurl4-openssl-dev libglpk-dev libgmp3-dev libxml2-dev > /dev/null 2>&1

echo '>>> Installing R package dependencies...'
Rscript -e \"install.packages(c('Rcpp', 'RcppArmadillo', 'sna', 'network', 'networkDynamic', 'Matrix', 'MASS', 'MatchIt', 'SparseM', 'boot', 'igraph', 'viridisLite', 'rcmdcheck', 'remotes', 'knitr'), repos='https://packagemanager.posit.co/cran/__linux__/noble/latest', quiet=TRUE)\"

echo '>>> Running R CMD check...'
Rscript -e \"rcmdcheck::rcmdcheck(args = c('--no-manual', '--as-cran'), error_on = 'warning', check_dir = 'check')\"
" && echo -e "${GREEN}✓ Ubuntu check passed${NC}" || echo -e "${RED}✗ Ubuntu check failed${NC}"
;;

macos|mac)
echo -e "${YELLOW}macOS checks require macOS host - skipped${NC}"
echo "To test on macOS, run: R CMD build . && R CMD check --as-cran *.tar.gz"
;;

windows|win)
echo -e "${YELLOW}Windows checks require Windows host - skipped${NC}"
echo "To test on Windows, use rhub or GitHub Actions"
;;

all)
echo -e "${BLUE}Running all available checks...${NC}"
$0 ubuntu
;;

*)
echo -e "${RED}Unknown platform: $PLATFORM${NC}"
echo "Usage: $0 [ubuntu|macos|windows|all]"
exit 1
;;
esac

echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Local check completed!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo "Note: This simulates GitHub Actions but may have minor differences."
echo "For exact GitHub Actions behavior, push to a branch and create a PR."
echo ""
5 changes: 3 additions & 2 deletions src/infection.cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copilot was fixing this in #60. Just closed that in favor of this.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
#include <cmath>
using namespace Rcpp;

// [[Rcpp::export]]
Expand Down Expand Up @@ -55,7 +56,7 @@ NumericVector infection_cpp(
Rcpp::checkUserInterrupt();

// If NA (aka nan in Armadillo), then NA.
if (!arma::is_finite(times(i))) {
if (!std::isfinite(times(i))) {
infect.at(i) = NA_REAL;
continue;
}
Expand Down Expand Up @@ -159,7 +160,7 @@ NumericVector susceptibility_cpp(
Rcpp::checkUserInterrupt();

// If NA (aka nan in Armadillo), then NA.
if (!arma::is_finite(times(i))) {
if (!std::isfinite(times(i))) {
suscep.at(i) = NA_REAL;
continue;
}
Expand Down
Loading