Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaging now works. Updated the DESCRIPTION #3

Open
wants to merge 31 commits into
base: r_replication
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d2c8884
Packaging now works. Updated the DESCRIPTION
Kemuk Oct 31, 2024
51772b2
Commented out the environment line
Kemuk Oct 31, 2024
110d6c4
Imported the library instead of calling conda
Kemuk Oct 31, 2024
3d27693
Adjusted pkgdown.yaml to create Python Env
Kemuk Oct 31, 2024
a045981
Ammended pkgdown to work on pull request
Kemuk Oct 31, 2024
7b40bdc
Ammended MacOS testing
Kemuk Oct 31, 2024
607a854
Ammended the .Rbuildignore
Kemuk Oct 31, 2024
9d580d7
Commented out the rEpiabm line
Kemuk Oct 31, 2024
9735f13
Creating a workaround by creating a py env
Kemuk Oct 31, 2024
8774287
Created workaround in zzz.R that passed locally
Kemuk Nov 1, 2024
675bfb6
Ammended MacOS workflow
Kemuk Nov 1, 2024
7f95fc1
Ammended MacOS workflow
Kemuk Nov 1, 2024
14f6422
Fix MacOS workflow to activate environment
Kemuk Nov 1, 2024
2ccf778
Using simulation dataframe instead of tidyr
Kemuk Nov 1, 2024
04a30e8
Fixed the tidyr
Kemuk Nov 1, 2024
65739cc
Included tidyr into DESCRIPTION
Kemuk Nov 1, 2024
100a6bb
Removed print statements
Kemuk Nov 1, 2024
8181479
Ammended simulation flow check to read R directly
Kemuk Nov 1, 2024
a2a6437
Updated yaml files
Kemuk Nov 1, 2024
150c189
Updated test_windows.yml with x64 architecture
Kemuk Nov 1, 2024
941a6bb
Switched windows to 32-bit (x86 architecture)
Kemuk Nov 1, 2024
61ec97f
Made sure that Python is 64 bit in the yml
Kemuk Nov 1, 2024
3c8ac8a
Changed from 64 bit compilers to 32 bit ones
Kemuk Nov 1, 2024
a56cfcd
Disabled the multiarch
Kemuk Nov 1, 2024
7d9faa4
.Rbuildignore updated
Kemuk Nov 1, 2024
a99924a
Updated the DESCRIPTION and the ignore file
Kemuk Nov 1, 2024
b187170
Fixed Description
Kemuk Nov 1, 2024
89e7326
New attempt to get R working for windows
Kemuk Nov 1, 2024
9e7d85f
Updated rcmdcheck with multiarch
Kemuk Nov 1, 2024
e350ec6
Fixed quotation error in windows yml
Kemuk Nov 1, 2024
da8deb0
Rolled back windows.yml
Kemuk Nov 1, 2024
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
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.10'

- 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
65 changes: 60 additions & 5 deletions .github/workflows/test_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ name: "Unit tests: macOS"
on:
push:
branches:
- main
- '**'
pull_request:
branches:
- '**'

jobs:

test:
name: tests on macOS with R ${{ matrix.R }}
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
R: [ '4.1.0' ]
R: ['4.1.0']

steps:

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

Expand All @@ -28,6 +26,11 @@ jobs:
with:
r-version: ${{ matrix.R }}
Ncpus: 2

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Query dependencies
run: |
Expand All @@ -51,6 +54,58 @@ jobs:
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: setup r-reticulate venv
shell: Rscript {0}
run: |
library(reticulate)

reticulate::py_run_string("
import sys
import subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip'])
")

# Install required packages
reticulate::py_run_string("
import sys
import subprocess

# Install basic packages
packages = ['numpy', 'pandas', 'matplotlib']
for package in packages:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', package])

# Install pyEpiabm from GitHub
subprocess.check_call([
sys.executable, '-m', 'pip', 'install', '--upgrade',
'git+https://github.com/SABS-R3-Epidemiology/epiabm.git@main#egg=pyEpiabm&subdirectory=pyEpiabm'
])
")

env_name <- "r-py-env"
python_version = "3.9"
tryCatch({
# Check if virtualenv package is available
if (!reticulate::virtualenv_exists(env_name)) {
message(sprintf("Creating new Python virtual environment: %s", env_name))

# Create virtual environment with system site packages to help with SSL
reticulate::virtualenv_create(
envname = env_name,
version = python_version,
packages = "pip",
system_site_packages = TRUE
)
}

# Activate the environment
reticulate::use_virtualenv(env_name, required = TRUE)
return(TRUE)
}, error = function(e) {
warning(sprintf("Failed to create/activate Python environment: %s", e$message))
return(FALSE)
})

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
Expand All @@ -62,4 +117,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
14 changes: 7 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,7 +18,6 @@ jobs:
R: [ '4.1.0' ]

steps:

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

Expand All @@ -28,22 +26,24 @@ jobs:
with:
r-version: ${{ matrix.R }}
Ncpus: 2

architecture: 'x64'
multiarch: false

- 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 @@ -62,4 +62,4 @@ jobs:
- 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
Loading