Testing package with C++ function in GitHub Actions throws error: R is already initialized

42 Views Asked by At

When I R CMD check my package on GitHub Actions, I am getting the error "R is already initialized", during the tests, and only on Ubuntu. Tests run ok in MacOs and Windows.

test_that("option 1: fully pre-specified settings file works", {
  ### Tests for EXPLORE using iris dataset
  data_path <- system.file("examples", "iris.arff", package = "Explore")
  settings_path <- system.file("examples", "iris.project", package = "Explore")
  output_path <- paste0(tempdir(), "/", "Test1")
  dir.create(output_path)
  if (.Platform$OS.type == "windows") {
    output_path <- gsub("\\\\", "/", output_path)
  }
  output_path <- paste0(output_path, "/")
  data <- farff::readARFF(data_path)
  model <- Explore::trainExplore(output_path = output_path,
                                 file_name = "iris",
                                 train_data = data,
                                 ClassFeature = "'class'",
                                 PositiveClass = '"Iris-versicolor"')
  expect_equal(class(model), "character")
  # expect_true(is.na(model), info = "Test failed because model is NA")
  expect_equal(model, "'petallength'>2.45AND'petallength'<=4.95AND'petalwidth'<=1.65")
})

It seems that when the trainExplore() runs, that includes a C++ code with rcppp, another instance of R initialize, and that brings the error.

── Test failures ───────────────────────────────────────────────── testthat ────

> library(testthat)
> library(Explore)
> 
> test_check("Explore")
Parse with reader=readr : /home/runner/work/Explore/Explore/check/Explore.Rcheck/Explore/examples/iris.arff
Loading required package: readr

Attaching package: 'readr'

The following objects are masked from 'package:testthat':

    edition_get, local_edition

header: 0.063000; preproc: 0.000000; data: 0.108000; postproc: 0.000000; total: 0.171000
Error: Error: R CMD check found ERRORs
R is already initialized
Execution halted

**Workflow config: **

# 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, develop, OmmitedSrcFiles]
  pull_request:
    branches: [main, develop, OmmitedSrcFiles]

name: R-CMD-check

jobs:
  R-CMD-check:
    runs-on: ${{ matrix.config.os }}

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

    strategy:
      fail-fast: false
      matrix:
        config:
          - {os: macos-latest,   r: 'release'}
          - {os: windows-latest, r: 'release'}
          - {os: ubuntu-latest,   r: 'devel', http-user-agent: 'release'}
          - {os: ubuntu-latest,   r: 'release'}
          - {os: ubuntu-latest,   r: 'oldrel-1'}

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

    steps:
      - uses: actions/checkout@v3

      - 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-r-dependencies@v2
        with:
          extra-packages: any::rcmdcheck
          needs: check

      - uses: r-lib/actions/check-r-package@v2
        with:
          upload-snapshots: true
          error-on: '"error"'
0

There are 0 best solutions below