Skip to content
Open
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
38 changes: 31 additions & 7 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,67 @@ on:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} (${{ matrix.r }})
name: ${{ matrix.os }} (${{ matrix.r }}) - ${{ matrix.backend }}

strategy:
fail-fast: false
matrix:
include:
- { os: "ubuntu-latest", python: "3.13", r: "release" }
- { os: "windows-latest", python: "3.13", r: "release" }
- { os: "macOS-latest", python: "3.13", r: "release" }
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-1" }
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-2" }
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-3" }
- { os: "ubuntu-latest", python: "3.13", r: "release", backend: "venv" }
- { os: "ubuntu-latest", python: "3.13", r: "release", backend: "conda" }

- { os: "windows-latest", python: "3.13", r: "release", backend: "venv" }
- { os: "windows-latest", python: "3.13", r: "release", backend: "conda" }

- { os: "macOS-latest", python: "3.13", r: "release", backend: "venv" }
- { os: "macOS-latest", python: "3.13", r: "release", backend: "conda" }

- { os: "ubuntu-latest", python: "3.10", r: "oldrel-1", backend: "venv" }
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-2", backend: "venv" }
- { os: "ubuntu-latest", python: "3.10", r: "oldrel-3", backend: "venv" }

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
MPLBACKEND: Agg
ACRO_USE_CONDA: ${{ matrix.backend == 'conda' && 'true' || 'false' }}

steps:
- name: Checkout ACRO
uses: actions/checkout@v4

- name: Setup Miniconda
if: matrix.backend == 'conda'
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python }}
auto-activate-base: false

- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python }}

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

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.r }}

- name: Install R dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- name: Check R Package
uses: r-lib/actions/check-r-package@v2
with:
Expand Down
92 changes: 88 additions & 4 deletions R/acro_init.R
Copy link
Collaborator

@jim-smith jim-smith Jan 15, 2026

Choose a reason for hiding this comment

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

  1. Do we want to tie this to a specific version of acro ( could understand 'yes, for now')
  2. This seems to use python 12 (maybe becuase that is what is on condo?), and maybe it is how the file was shown to me, but R-CMD-check.yaml seemed ot refer only to 10 or 13
  3. there's an error message saying something like "miniconda is not installed". Should that use parenthesis in case people don't understand the relationship I.e. "...(mini) conda is not installed..."
  4. This does not give people the ability to provide a config file when they call init (line 92). I know it is a slightly different issues, but ...

Copy link
Collaborator Author

@rpreen rpreen Jan 15, 2026

Choose a reason for hiding this comment

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

  1. It is pinned to Python ACRO v0.4.11 - we have always pinned ACRO-R to a specific Python version for stability; it does mean that the CRAN package needs updating each time the Python backend is updated, but it's safer and allows changes to occur upstream without breaking anything here.
  2. The Conda Python is set to Python 3.12 because it is probably the most stable version; and since Conda allows specifying a specific version it reduces the number of moving parts. The CI uses Python 3.12 so we only need to test it - hence fewer CI runners needed. If Conda is not used then the virtual environment will use whatever Python is available on the system (>=3.10) as before.
  3. Changed "miniconda" to just "conda".
  4. Done.

Original file line number Diff line number Diff line change
@@ -1,12 +1,96 @@
# Globals -----------------------------------------------------------------
acro_venv <- "r-acro"
acro_pkg <- "acro==0.4.11"
ch <- "conda-forge"


# Internal helper: resolve Python executable
## nocov start
get_python <- function() {
python <- Sys.which("python3")
if (python == "") {
python <- Sys.which("python")
if (python == "") {
stop("Python not found in PATH. Please ensure Python is installed.")
}
}
return(python)
}
## nocov end


# Internal helper: install ACRO in a Conda environment
## nocov start
install_conda <- function(envname) { # nocov
if (!reticulate::condaenv_exists(envname = envname, conda = "auto")) {
reticulate::conda_create(envname = envname, python_version = "3.12", channel = ch)
reticulate::conda_install(envname = envname, packages = acro_pkg, channel = ch)
}
}
## nocov end


# Internal helper: install ACRO in a Python virtual environment
install_venv <- function(envname = acro_venv) {
if (!reticulate::virtualenv_exists(envname)) {
python <- get_python()

reticulate::virtualenv_create(
envname = envname,
python = python,
force = TRUE,
packages = NULL
)

reticulate::py_install(acro_pkg, envname = envname)
}
}


# Internal helper: resolve whether Conda should be used
get_use_conda <- function(use_conda = NULL) {
if (is.null(use_conda)) {
use_conda <- tolower(Sys.getenv("ACRO_USE_CONDA")) %in% c("1", "true", "yes")
}
use_conda <- isTRUE(use_conda) # default FALSE

if (use_conda && is.null(reticulate::conda_binary())) { # nocov
stop("Conda requested but no conda installation found", call. = FALSE) # nocov
}

return(use_conda)
}


#' Initialise an ACRO object
#'
#' @param config Name of a yaml configuration file with safe parameters.
#' @param suppress Whether to automatically apply suppression.
#' @param envname Name of the Python environment to use.
#' @param use_conda Whether to use a Conda environment.
#' If `NULL`, looks for environment variable `ACRO_USE_CONDA`,
#' defaults to `FALSE` if unset.
#'
#' @return No return value, called for side effects
#' @return Invisibly returns the ACRO object, which is used internally.
#' @export
acro_init <- function(config = "default", suppress = FALSE, envname = acro_venv, use_conda = NULL) {
# define the environment
use_conda <- get_use_conda(use_conda)

acro_init <- function(suppress = FALSE) {
create_virtualenv()
# initialise the environment
if (!reticulate::py_available(initialize = FALSE)) {
if (use_conda) { # nocov
install_conda(envname) # nocov
reticulate::use_condaenv(envname, required = TRUE) # nocov
} else {
install_venv(envname)
reticulate::use_virtualenv(envname, required = TRUE)
}
}

# import the acro package and instantiate an object
acro <- reticulate::import("acro", delay_load = TRUE)
acroEnv$ac <- acro$ACRO(suppress = suppress)
acroEnv$ac <- acro$ACRO(config = config, suppress = suppress)

invisible(acroEnv$ac)
}
55 changes: 0 additions & 55 deletions R/create_virtualenv.R

This file was deleted.

17 changes: 15 additions & 2 deletions man/acro_init.Rd

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

17 changes: 0 additions & 17 deletions man/create_virtualenv.Rd

This file was deleted.

21 changes: 0 additions & 21 deletions man/install_acro.Rd

This file was deleted.

18 changes: 0 additions & 18 deletions tests/testthat/test-create_virtualenv.R

This file was deleted.

2 changes: 1 addition & 1 deletion tests/testthat/test-install_acro.R
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we have a test for install_conda ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's time consuming to create a single runner that will test both Conda and venv just so the code coverage can be contained. The CI has dedicated runners for Conda now which execute the tests in that environment (except for one specific test that tests installation in a venv that I kept because it was originally there --- I wonder if it's even necessary since if that fails then none of the tests would pass.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

sounds good.
Appreciate your adding the unrelated feature about handling config files
should we add a test to check the custom yaml has been loaded or do that elsewhere?

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("install_acro installs 'acro' in the specified environment", {
test_envname <- "test-acro-env"

# Run the install_acro function
install_acro(envname = test_envname)
install_venv(envname = test_envname)

# Check if 'acro' is installed in the test environment
is_installed <- reticulate::py_module_available("acro")
Expand Down
Loading