Skip to content

Commit

Permalink
Merge branch 'r_replication_k' into r_replication
Browse files Browse the repository at this point in the history
  • Loading branch information
Kemuk committed Jan 14, 2025
2 parents 66444eb + b514f21 commit b2446d1
Show file tree
Hide file tree
Showing 16 changed files with 364 additions and 37 deletions.
12 changes: 12 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
^codecov\.yml$
^CRAN-RELEASE$
^cran-comments\.md$
^\.github$
^doc$
^Meta$
^windows\\i386\*
^i386\.*$
.lintr
17 changes: 14 additions & 3 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches:
- '**'
pull_request:
branches:
- '**'
release:
types: [published]
workflow_dispatch:
Expand All @@ -28,9 +32,16 @@ jobs:
extra-packages: any::pkgdown, local::., any::XML
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
- uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Setup r-reticulate env
run: reticulate::virtualenv_create("r-reticulate", Sys.which("python"))
shell: Rscript {0}

- name: Build site
run: Rscript -e "pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)"

- name: Deploy to GitHub pages
if: github.event_name != 'pull_request'
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/test_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "Unit tests: macOS"
on:
push:
branches:
- main
- '**'
pull_request:
branches:
- '**'
Expand All @@ -22,6 +22,10 @@ jobs:

- name: Checkout repository
uses: actions/checkout@v2

- name: Install build dependencies
run: |
brew install curl
- name: Setup R
uses: r-lib/actions/setup-r@v2
Expand Down Expand Up @@ -49,6 +53,7 @@ jobs:
install.packages(c("devtools"))
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
reticulate::install_python(version = "3.9:latest")
shell: Rscript {0}

- name: Check
Expand All @@ -62,4 +67,4 @@ jobs:
- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/test_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "Unit tests: Ubuntu"
on:
push:
branches:
- main
- '**'
pull_request:
branches:
- '**'
Expand Down
29 changes: 22 additions & 7 deletions .github/workflows/test_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ name: "Unit tests: Windows"
on:
push:
branches:
- main
- '**'
pull_request:
branches:
- '**'

jobs:

test:
name: tests on Windows with R ${{ matrix.R }}
runs-on: windows-latest
Expand All @@ -19,6 +18,13 @@ jobs:
R: [ '4.1.0' ]

steps:
- name: Check Windows architecture
run: |
if (-not [Environment]::Is64BitOperatingSystem) { throw "Not 64-bit Windows" }
Write-Host "OS Architecture: $([Environment]::Is64BitOperatingSystem)"
Write-Host "Process Architecture: $([Environment]::Is64BitProcess)"
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type"
shell: pwsh

- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -28,22 +34,31 @@ jobs:
with:
r-version: ${{ matrix.R }}
Ncpus: 2

r-arch: 'x64'

- name: Verify R architecture
run: |
Rscript -e "if(R.version$arch != 'x64') stop('R architecture is not 64-bit!')"
Rscript -e "cat('R Architecture:', R.version$arch, '\n')"
Rscript -e "cat('.Machine$sizeof.pointer:', .Machine$sizeof.pointer, '\n')"
Rscript -e "cat('Using R at:', R.home(), '\n')"
shell: cmd

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
shell: Rscript {0}

- name: cache R installed packages
- name: Cache R packages
uses: actions/[email protected]
id: cache
with:
path: |
${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-R${{ matrix.R }}-2-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-R${{ matrix.R }}-2-

- name: Install packages
run: |
install.packages(c("devtools"))
Expand All @@ -56,10 +71,10 @@ jobs:
_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")
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran" ,'--no-multiarch'), error_on = "error", check_dir = "check")
shell: Rscript {0}

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash
shell: bash
17 changes: 10 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Type: Package
Title: R-Wrapper of Epiabm
Version: 0.0.2
Authors@R: c(
person('Anita', 'Applegarth', role = c('aut', 'cre', 'cph'), email = 'anita.applegarth@reub.ox.ac.uk'),
person('Anita', 'Applegarth', role = c('aut', 'cre', 'cph'), email = 'anita.applegarth@reuben.ox.ac.uk'),
person('Kingsley', 'Oguma', role = 'aut', email = "[email protected]")
)
Description: Wraps the epiabm Python module in R.
Expand All @@ -12,20 +12,23 @@ Encoding: UTF-8
Archs: x64
SystemRequirements: Python (>= 2.7.0)
Suggests: tinytest
Imports: ggplot2, here
Depends:
reticulate (>= 1.14),
R (>= 3.3.0)
Imports:
ggplot2,
here,
tidyr,
reticulate (>= 1.14)
Depends: R (>= 3.3.0)
Config/reticulate:
list(
packages = list(
list(package = "numpy", pip = TRUE),
list(package = "pandas", pip = TRUE),
list(package = "pandas", pip = TRUE),
list(package = "matplotlib", pip = TRUE),
list(
package = "pyEpiabm",
pip = TRUE,
pip_options = "--index-url git+https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm&subdirectory=pyEpiabm"
pip_options = "--extra-index-url https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm&subdirectory=pyEpiabm"
)
)
)
RoxygenNote: 7.3.2
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import(reticulate)
# Generated by roxygen2: do not edit by hand

export(check_python_env)
export(initialize_python_env)
35 changes: 19 additions & 16 deletions R/simulation_flow_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
# Example simulation script with data output
#
# Import dependencies
source("R/zzz.R")
initialize_python_env()
check_python_env()

library(reticulate)
#library(rEpiabm)
library(here)
library(tidyr)

os <- import("os")
logging <- import("logging")
pd <- import("pandas")
plt <- import("matplotlib.pyplot")
pe <- import("pyEpiabm")
os <- import("os", delay_load = TRUE)
logging <- import("logging", delay_load = TRUE)
pd <- import("pandas", delay_load = TRUE)
plt <- import("matplotlib.pyplot", delay_load = TRUE)
pe <- import("pyEpiabm", delay_load = TRUE)

# Set working directory for relative directory references
base_dir <- here()
Expand Down Expand Up @@ -91,12 +96,8 @@ sim$compress_csv()

# Create dataframe for plots
filename <- here("simulation_outputs", "output.csv")
df <- pd$read_csv(filename)
df <- read.csv(filename)

# Convert pandas dataframe to R dataframe
df_r <- as.data.frame(df)

# Load library for plotting
library(ggplot2)

# Reshape the data from wide to long format using base R
Expand All @@ -105,13 +106,15 @@ status_columns <- c("InfectionStatus.Susceptible",
"InfectionStatus.Recovered",
"InfectionStatus.Dead")

df_long <- data.frame(
time = rep(df_r$time, length(status_columns)),
Status = factor(rep(status_columns, each = nrow(df_r)),
levels = status_columns,
labels = c("Susceptible", "Infected", "Recovered", "Dead")),
Count = unlist(df_r[status_columns])
df_long <- pivot_longer(
df,
cols = all_of(status_columns),
names_to = "Status",
values_to = "Count"
)
df_long$Status <- factor(df_long$Status,
levels = status_columns,
labels = c("Susceptible", "Infected", "Recovered", "Dead"))

# Create the plot
p <- ggplot(df_long, aes(x = time, y = Count, color = Status)) +
Expand Down
Loading

0 comments on commit b2446d1

Please sign in to comment.