diff --git a/.Rbuildignore b/.Rbuildignore index 70c8982..d2714dc 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -15,3 +15,14 @@ ^data/nursery\.arff$ ^data/charity\.dta$ ^prepare_to_submit_to_CRAN\.R$ +^pkgdown$ +^index\.md$ +^examples\.md$ +^installation\.md$ +^supports\.md$ +^welcome\.md$ +^\.vscode$ +^.*\.swp$ +^\.Rdata$ +^doc$ +^Meta$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index a44d764..cd48a0e 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,65 +1,45 @@ -# 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] pull_request: branches: [main, master] - name: R-CMD-check - jobs: R-CMD-check: runs-on: ${{ matrix.os }} - name: ${{ matrix.os }} (${{ matrix.r }}) - strategy: fail-fast: false matrix: include: - - # default everything - - {os: 'ubuntu-latest', python: '3.13', r: 'release'} - - {os: 'windows-latest', python: '3.13', r: 'release'} - - {os: 'macOS-latest', python: '3.13', r: 'release'} - - # older R versions - - {os: 'ubuntu-latest', python: '3.9', r: 'oldrel-1'} - - {os: 'ubuntu-latest', python: '3.9', r: 'oldrel-2'} - - {os: 'ubuntu-latest', python: '3.9', r: 'oldrel-3'} - + - { 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" } env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes - # set matplotlib backend because Windows CI errors with: - # "This probably means that Tcl wasn't installed properly." - MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434 - + MPLBACKEND: Agg steps: - name: Checkout ACRO - uses: actions/checkout@v5 - + uses: actions/checkout@v4 - 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: diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index cdc87ce..0a6156d 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -14,12 +14,6 @@ jobs: pkgdown: runs-on: ubuntu-latest - concurrency: # restrict concurrency for non-PR jobs - group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} - - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - steps: - name: Checkout uses: actions/checkout@v5 diff --git a/.gitignore b/.gitignore index bc5e4ee..7cddaf5 100644 --- a/.gitignore +++ b/.gitignore @@ -148,3 +148,6 @@ stata/various_stata_development__files # test output /outputs/ /test.xlsx +inst/doc +/doc/ +/Meta/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d3df8b..1f6471a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,7 +34,8 @@ repos: (?x)^( .*\.txt| .*\.ipynb| - .*\.html + .*\.html| + docs/deps/.* )$ # Format R files diff --git a/DESCRIPTION b/DESCRIPTION index b4e2d25..dae5bc7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,7 +13,7 @@ Description: A Tool for Semi-Automating the Statistical Disclosure Control of Re License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 SystemRequirements: Python (>= 3.10) Imports: reticulate, @@ -23,9 +23,12 @@ Depends: R (>= 2.10) LazyData: true Suggests: + knitr, + rmarkdown, spelling, testthat (>= 3.0.0) Config/testthat/edition: 3 Language: en-US URL: https://github.com/AI-SDC/ACRO-R BugReports: https://github.com/AI-SDC/ACRO-R/issues +VignetteBuilder: knitr diff --git a/R/create_virtualenv.R b/R/create_virtualenv.R index 54386ff..55fdd5a 100644 --- a/R/create_virtualenv.R +++ b/R/create_virtualenv.R @@ -2,20 +2,29 @@ acro_venv <- "r-acro" acro_package <- "acro==0.4.11" python_version <- ">=3.10" - #' Install acro #' #' @param envname the name of the Python virtual environment +#' @param python the path to Python executable #' @param ... Any other parameters. #' #' @return No return value, called for side effects +install_acro <- function(envname = "r-acro", python = NULL, ...) { + # Get Python executable if not provided + if (is.null(python)) { + python <- Sys.which("python3") + if (python == "") { + python <- Sys.which("python") # nocov + if (python == "") { # nocov + stop("Python not found in PATH. Please ensure Python is installed and accessible.") # nocov + } # nocov + } + } - -install_acro <- function(envname = "r-acro", ...) { # create Python virtual environment reticulate::virtualenv_create( envname = envname, - version = python_version, + python = python, force = TRUE, packages = NULL ) @@ -29,11 +38,16 @@ install_acro <- function(envname = "r-acro", ...) { #' @param ... Any other parameters. #' #' @return No return value, called for side effects - create_virtualenv <- function(...) { + # Get Python executable path + python_path <- Sys.which("python3") + if (python_path == "") { + python_path <- Sys.which("python") # nocov + } + # ensure a virtual environment exists if (!reticulate::virtualenv_exists(acro_venv)) { - install_acro(envname = acro_venv) + install_acro(envname = acro_venv, python = python_path) } # activate virtual environment diff --git a/_pkgdown.yml b/_pkgdown.yml index 5d0f29c..b74690f 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,5 +1,27 @@ ---- -url: https://AI-SDC.github.io/ACRO-R/ template: + light-switch: true bootstrap: 5 -... + bslib: + primary: "#0051a5" + +navbar: + structure: + left: [home, reference, welcome, supports, installation, examples] + right: [search, github, lightswitch] + left: + - text: "Home" + href: index.html + - text: "Reference" + href: reference/index.html + - text: "Welcome to ACRO-R" + href: welcome.html + - text: "What ACRO-R Supports" + href: supports.html + - text: "Installation" + href: installation.html + - text: "Examples" + href: examples.html + right: + - icon: fab-github + href: https://github.com/AI-SDC/ACRO-R + aria-label: GitHub diff --git a/inst/WORDLIST b/inst/WORDLIST index 50102c4..93cbbdf 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -2,27 +2,40 @@ ADR Acknowledgement Analytics EPSRC +GPLv GRAIMATTER HDR Initialise Karnofsky MRC MyBinder +NK +PyPI RStudio SACRO SDC +Scalable +TRE Xplore auditable +btn codecov +crosstab disclosive +finalise github https initialised json +mitigations numpy openml +organisation pre programme +sacro scipy +sm +statsmodels www xlsx diff --git a/inst/examples.md b/inst/examples.md new file mode 100644 index 0000000..c6168ef --- /dev/null +++ b/inst/examples.md @@ -0,0 +1,40 @@ +# Examples + +## Interactive Notebook + +For comprehensive examples and tutorials, see our interactive R notebook: + +[Example Notebook](articles/example-notebook.html) + +## Quick Start Examples + +### Basic Usage + +```r +library("acro") + +# Initialize ACRO +acro_init(suppress = TRUE) + +# Your analysis code here +# ACRO will automatically check outputs for disclosure risks +``` + +### Creating Safe Tables + +```r +# Example of creating a cross-tabulation with ACRO +result <- acro_crosstab(data$variable1, data$variable2) + +# ACRO automatically applies disclosure control +print(result) +``` + +### Finalizing Your Session + +```r +# When you're done with your analysis +acro_finalise() +``` + +For more detailed examples and use cases, please refer to the [Example Notebook](articles/example-notebook.html). diff --git a/inst/index.md b/inst/index.md new file mode 100644 index 0000000..a63d5fd --- /dev/null +++ b/inst/index.md @@ -0,0 +1,49 @@ +Alt Text + +## AI-SDC Family Tools + +| **ACRO (Python)** | **SACRO-ML** | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **Statistical Disclosure Control for Python**
Tools for the Semi-Automatic Checking of Research Outputs. Drop-in replacements for common analysis commands with built-in privacy protection.
[Statistical Analysis](https://sacro-tools.org/introduction.html){.btn .btn-acro .btn-sm} | **Machine Learning Privacy Tools**
Collection of tools and resources for managing the statistical disclosure control of trained machine learning models.
[Learn More](https://SACRO-ML.sacro-tools.org/introduction.html){.btn .btn-sacro-ml .btn-sm} | +| **ACRO-R** | **SACRO-Viewer** | +| **R Package Integration**
R-language interface for the Python ACRO library, providing familiar R syntax for statistical disclosure control.
[R Integration](reference/index.html){.btn .btn-acro-r .btn-sm} | **Graphical User Interface**
A graphical user interface for fast, secure and effective output checking, which can work in any TRE (Trusted Research Environment).
[View Docs](https://SACRO-Viewer.sacro-tools.org/introduction.html){.btn .btn-sacro-viewer .btn-sm} | + +## ACRO-R: Statistical Disclosure Control + +ACRO is a free and open source tool that supports the semi-automated checking of research outputs (SACRO) for privacy disclosure within secure data environments. SACRO is a framework that applies best-practice principles-based statistical disclosure control (SDC) techniques on-the-fly as researchers conduct their analysis. SACRO is designed to assist human checkers rather than seeking to replace them as with current automated rules-based approaches. + +## What is ACRO-R? + +ACRO implements a principles-based statistical disclosure control (SDC) methodology that: + +* Automatically identifies potentially disclosive outputs +* Applies optional disclosure mitigation strategies +* Reports reasons for applying SDC +* Produces summary documents for output checkers + +## Core Features + +### Semi-Automated Disclosure Checking + +* **Drop-in replacements** for common Python analysis commands (pandas, statsmodels, etc.) with configurable disclosure checks +* **Automated sensitivity tests** : frequency thresholds, dominance (p%, NK rules, etc.), residual degrees-of-freedom checks +* **Optional mitigations** : suppression, rounding, and more to come +* **Session management** : track, rename, comment, remove, add exceptions, and finalise reports +* **Configurable risk parameters** via YAML files +* **Generates auditable reports** in JSON or Excel + +### Design Principles + +* **Free and open source** under MIT (ACRO) / GPLv3 (SACRO Viewer) +* **Easy to install** via PyPI, CRAN, or GitHub; cross-platform (Linux, macOS, Windows) +* **Familiar APIs** - same function signatures as native commands: acro.crosstab mirrors pandas.crosstab, etc. +* **Comprehensive coverage** - tables, regressions, histograms, survival plots, etc. +* **Transparent & auditable** - clear reports, stored queries, designed for human-checkers +* **Configurable & extensible** - organisation-defined disclosure rules, multi-language support +* **Scalable** - lightweight, session-based, local execution + +## Getting Started + +| **Install** | **Learn** | **Reference** | +| ------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | +| Get ACRO-R installed and configured in your environment
[Install Guide](articles/installation.html){.btn .btn-primary} | Explore tutorials and examples for common use cases
[Examples](articles/index.html){.btn .btn-primary} | Complete API documentation and function reference
[API Docs](reference/index.html){.btn .btn-primary} | diff --git a/inst/installation.md b/inst/installation.md new file mode 100644 index 0000000..901fd23 --- /dev/null +++ b/inst/installation.md @@ -0,0 +1,50 @@ +# Installation Guide + +## Install from CRAN + +Install the **acro** package from CRAN as follows: + +```r +install.packages("acro") +``` + +## Development Version + +To install the development version from GitHub: + +```r +# Install devtools if you haven't already +install.packages("devtools") + +# Install ACRO-R from GitHub +devtools::install_github("AI-SDC/ACRO-R") +``` + +## Prerequisites + +ACRO-R requires: +- R version 4.0 or higher +- Python 3.10+ or higher with the ACRO Python package installed + +## Python ACRO Installation + +The R package interfaces with the Python ACRO library. Install it using: + +```bash +pip install acro +``` + +## Troubleshooting + +If you are having problems installing the package, please see the more detailed [installation guide](INSTALL.md) or check the [GitHub issues](https://github.com/AI-SDC/ACRO-R/issues). + +## Verification + +To verify your installation works correctly: + +```r +library("acro") +acro_init(suppress = TRUE) +``` + +If this runs without errors, your installation is successful! diff --git a/inst/supports.md b/inst/supports.md new file mode 100644 index 0000000..b18267d --- /dev/null +++ b/inst/supports.md @@ -0,0 +1,123 @@ +# What ACRO-R Supports + + +This page provides a comprehensive overview of ACRO’s capabilities for researchers, developers, and non-technical stakeholders. ACRO supports a wide range of statistical analysis functions with automated disclosure control. + +## Supported Data Analysis Functions + +### Table Creation & Cross-tabulation + +**For Researchers:** Create frequency tables and cross-tabulations with automatic cell suppression for small counts. + +**What ACRO Supports:** + +* **crosstab()** - Cross-tabulation of two or more variables with frequency counting +* **pivot_table()** - Spreadsheet-style pivot tables with aggregation functions +* **table()** - Simple frequency tables for categorical data (R interface only) + +**Technical Details:** - ACRO suppresses, and reports the reason why, the value of an aggregation statistic (mean, median, variance, etc.) for any cell is deemed to be sensitive - The current version of ACRO supports the three most common tests for sensitivity: ensuring the number of contributors is above a frequency threshold, and testing for dominance via N-K rules - **N-K Rule** : A dominance test where if the top N contributors account for more than K% of the total, the cell is considered disclosive - **Frequency Threshold** : Cells with fewer than a specified number of contributors are suppressed - All thresholds are configurable via YAML configuration files - For detailed methodology, see our [research paper](https://doi.org/10.1109/TP.2025.3566052) - Automatic flagging of negative or missing values for human review + +**Example Use Cases:** - Survey response analysis by demographics - Clinical trial outcome tables - Market research cross-tabulations - Educational assessment reporting + +### Statistical Modeling + +**For Researchers:** Run regression analyses with automated checks on model outputs and residual degrees of freedom. + +**What ACRO Supports:** + +* **ols()** - Ordinary Least Squares linear regression +* **logit()** - Logistic regression for binary outcomes +* **probit()** - Probit regression for binary outcomes + +**Technical Details:** - For regressions such as linear, probit, and logit, the tests verify that the number of residual degrees of freedom exceeds a threshold - Within the ACRO Python package, the functionality of the ‘ACRO’ class is split into a number of separate classes for maintainability and extensibility. A ‘Tables’ class contains the code necessary to perform disclosure checks on tabular data, such as crosstab. A separate ‘Regression’ class contains the code for checking regressions such as logit and probit + +**Example Use Cases:** - Economic modeling and policy analysis - Medical research and clinical studies - Social science research - Business analytics and forecasting + +## Programming Language Support + +### Python (Primary) + +**For Developers:** The ACRO package is a lightweight Python tool that sits over well-known analysis tools that produce outputs such as tables, plots, and statistical models + +**Supported Libraries:** - **Pandas** - For data manipulation and table creation - **Statsmodels** - For statistical modeling and regression analysis - **NumPy** - For numerical computations + +**Python Version Support:** - Python 3.10, 3.11, 3.12, 3.13 + +### R Language + +**For R Users:** Additional programming languages such as this R package are supported by providing front-end packages that interface with the core ACRO Python back-end + +**Integration Features:** - Native R syntax and workflows - R Markdown and Shiny application support - Tidyverse compatibility - CRAN package availability + +**Getting Started in R:** ``r`` ``library("acro")`` ``acro_init(suppress`` ``=`` ``TRUE)`` `` + +### Stata Integration + +**For Stata Users:** ACRO is designed to let you use familiar commands in R, Stata and Python + +**Features:** - Drop-in replacement for standard Stata commands - Familiar Stata syntax and workflows - Integration with existing Stata scripts + +## Disclosure Control Features + +### Automated Sensitivity Testing + +**What ACRO Checks:** + +**For Tables:** - Minimum cell counts (frequency thresholds) - Dominance rules (N-K rules for concentration) - Presence of negative or missing values + +**For Statistical Models:** - Residual degrees of freedom thresholds - Model fit diagnostics - Parameter significance testing + +**For Non-Technical Users:** ACRO automatically identifies when research outputs might reveal sensitive information about individuals or organizations, applying industry-standard privacy protection rules without requiring manual review of every result. + +### Output Management + +**What ACRO Provides:** + +* **Suppression Masks** - Clear indication of which results are hidden and why +* **Summary Reports** - Detailed explanation of all disclosure checks performed +* **Audit Trails** - Complete record of all analysis steps and decisions +* **Exception Handling** - Process for requesting release of flagged outputs + +**Workflow Integration:** The finalise function will: Check that each output with “fail” or “review” status has an exception, if not you will be asked to enter one. Write the outputs to a directory. This directory contains everything that the output checkers need to make a decision + +## Supported Environments + +### Research Environments + +**Where ACRO Works:** - Trusted Research Environments (TREs) - Data safe havens - Secure data centers - Academic research computing facilities - Government statistical offices - Healthcare research environments + +**Installation:** See [Installation](https://jessuwe.github.io/ACRO/installation.html) for complete installation instructions and system requirements. + +## Integration Capabilities + +### Analysis Workflows + +**For Research Teams:** ACRO integrates seamlessly into existing data analysis workflows, requiring minimal changes to current practices while adding comprehensive privacy protection. + +**Supported Workflows:** - Jupyter notebook analysis - R Markdown documents - Stata do-files and scripts - Batch processing and automation - Interactive analysis sessions + +**Data Sources:** - CSV and Excel files - Database connections - Survey data platforms - Administrative datasets - Clinical trial databases + +### Output Formats + +**What ACRO Produces:** - Standard CSV files for tables - JSON metadata files for automation - Excel workbooks for human reviewers + +**Review Process Support:** Compatible with SACRO-Viewer for interactive output review by data controllers and compliance officers. + +## Technical Architecture + +**For System Administrators:** + +**Core Technology:** Lightweight translation scripts intercept your commands and pass them through to a python ‘engine’, based on industry-standard packages that run your commands and perform statistical disclosure checks on them + +**System Requirements:** - Python 3.10+ runtime environment - Standard scientific computing libraries (pandas, numpy, statsmodels) - Minimal computational overhead - No external network dependencies during analysis + +**Security Features:** - Local processing only (no cloud dependencies) - Audit logging and tracking - Configurable disclosure thresholds - Role-based access controls (through integration with TRE systems) + +**Documentation and Support:** Standard Python coding and naming practices have been used throughout. GitHub continuous integration (CI) runners automatically generate and publish API documentation using the Python docstrings written in numpydoc format + +## What ACRO Does NOT Support + +**Current Limitations:** - Complex visualizations and plots (coming in future versions) - Time series analysis (specialized disclosure rules needed) - Machine learning models (use SACRO-ML for AI/ML workflows) - Real-time data streams - Distributed computing frameworks + +**Alternative Solutions:** - **SACRO-ML** - For machine learning and AI model disclosure control - **SACRO-Viewer** - For interactive output review and approval - **Traditional SDC tools** - For specialized use cases not covered by ACRO diff --git a/inst/welcome.md b/inst/welcome.md new file mode 100644 index 0000000..d3d2e78 --- /dev/null +++ b/inst/welcome.md @@ -0,0 +1,47 @@ +# Welcome to ACRO-R + +## ACRO: Tools for the Semi-Automatic Checking of Research Outputs + +[![IEEE Xplore](https://img.shields.io/badge/IEEE%20Xplore-10.1109/TP.2025.3566052-blue)](https://doi.org/10.1109/TP.2025.3566052) +[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://opensource.org/licenses/MIT) +[![CRAN](https://www.r-pkg.org/badges/version/acro)](https://CRAN.R-project.org/package=acro) +[![check](https://github.com/AI-SDC/ACRO-R/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/AI-SDC/ACRO-R/actions?query=workflow%3AR-CMD-check) +[![codecov](https://codecov.io/gh/AI-SDC/ACRO-R/graph/badge.svg?token=VxbjBHzeXU)](https://app.codecov.io/gh/AI-SDC/ACRO-R) + +This repository maintains the ACRO R package, which is an interface to the Python [ACRO](https://github.com/AI-SDC/ACRO) package. + +ACRO is a free and open source tool that supports the semi-automated checking of research outputs (SACRO) for privacy disclosure within secure data environments. SACRO is a framework that applies best-practice principles-based [statistical disclosure control](https://en.wikipedia.org/wiki/Statistical_disclosure_control) (SDC) techniques on-the-fly as researchers conduct their analysis. SACRO is designed to assist human checkers rather than seeking to replace them as with current automated rules-based approaches. + +The ACRO package is a lightweight Python tool that sits over well-known analysis tools that produce outputs such as tables, plots, and statistical models. This package adds functionality to: + +* automatically identify potentially disclosive outputs against a range of commonly used disclosure tests; +* apply optional disclosure mitigation strategies as requested; +* report reasons for applying SDC; +* and produce simple summary documents trusted research environment staff can use to streamline their workflow and maintain auditable records. + +This creates an explicit change in the dynamics so that SDC is something done with researchers rather than to them, and enables more efficient communication with checkers. + +A graphical user interface ([SACRO-Viewer](https://github.com/AI-SDC/SACRO-Viewer)) supports human checkers by displaying the requested output and results of the checks in an immediately accessible format, highlighting identified issues, potential mitigation options, and tracking decisions made. + +Additional programming languages such as this R package are supported by providing front-end packages that interface with the core ACRO Python back-end. + +## Usage + +Before using any function from the package, an acro object should be initialised using the following R code: + +```r +library("acro") +acro_init(suppress = TRUE) +``` + +## Documentation + +The github-pages contains pre-built [documentation](https://ai-sdc.github.io/ACRO-R/). + +Additionally, see our [paper describing the SACRO framework](https://doi.org/10.1109/TP.2025.3566052) to learn about its principles-based SDC methodology and usage. + +## Acknowledgement + +This work was funded by UK Research and Innovation under Grant Numbers MC_PC_21033 and MC_PC_23006 as part of Phase 1 of the Data and Analytics Research Environments UK ([DARE UK](https://dareuk.org.uk/)) programme, delivered in partnership with Health Data Research UK (HDR UK) and Administrative Data Research UK (ADR UK). The specific projects were Semi-Automatic checking of Research Outputs (SACRO; MC_PC_23006) and Guidelines and Resources for AI Model Access from Trusted Research environments (GRAIMATTER; MC_PC_21033). This project has also been supported by MRC and EPSRC [grant number MR/S010351/1]. + +![UK Research and Innovation](man/figures/UK_Research_and_Innovation_logo.svg){width="20%"} ![Health Data Research UK](man/figures/health-data-research-uk-hdr-uk-logo-vector.png){width="20%"} ![Logo](man/figures/logo_print.png){width="20%"} diff --git a/man/figures/SACRO_Logo_final.png b/man/figures/SACRO_Logo_final.png new file mode 100644 index 0000000..d5a8e80 Binary files /dev/null and b/man/figures/SACRO_Logo_final.png differ diff --git a/man/install_acro.Rd b/man/install_acro.Rd index df26d5e..f9ea752 100644 --- a/man/install_acro.Rd +++ b/man/install_acro.Rd @@ -4,11 +4,13 @@ \alias{install_acro} \title{Install acro} \usage{ -install_acro(envname = "r-acro", ...) +install_acro(envname = "r-acro", python = NULL, ...) } \arguments{ \item{envname}{the name of the Python virtual environment} +\item{python}{the path to Python executable} + \item{...}{Any other parameters.} } \value{ diff --git a/pkgdown/extra.css b/pkgdown/extra.css new file mode 100644 index 0000000..5cbaba3 --- /dev/null +++ b/pkgdown/extra.css @@ -0,0 +1,113 @@ + +:root { + --bs-primary: #0051a5; + --bs-primary-rgb: 0, 81, 165; + --bs-body-bg: #ffffff; + --bs-body-color: #212529; +} + + +[data-bs-theme="dark"] { + --bs-primary: #4dabf7; + --bs-primary-rgb: 77, 171, 247; + --bs-body-bg: #1a1d29; + --bs-body-color: #ffffff; +} + + +.navbar { + background-color: var(--bs-body-bg) !important; + border-bottom: 1px solid var(--bs-border-color); +} + + +[data-bs-theme="dark"] .navbar { + background-color: rgb(34, 40, 50) !important; +} + +.navbar-brand { + color: var(--bs-primary) !important; + font-weight: 600; +} + +.navbar-nav .nav-link { + color: var(--bs-body-color) !important; +} + +.navbar-nav .nav-link:hover { + color: var(--bs-primary) !important; +} + + +.btn-primary { + background-color: var(--bs-primary); + border-color: var(--bs-primary); +} + + +a { + color: var(--bs-primary); +} + + +.lightswitch { + padding: 0.25rem 0.5rem; + margin-left: 0.5rem; + border: 1px solid var(--bs-border-color); + border-radius: 0.375rem; + background: transparent; + color: var(--bs-body-color); + cursor: pointer; +} + +.lightswitch:hover { + background-color: var(--bs-secondary-bg); +} + +.btn-acro { + background-color: #276BE9; + border-color: #276BE9; + color: white; +} + +.btn-acro:hover { + background-color: #1e5bc7; + border-color: #1e5bc7; + color: white; +} + +.btn-sacro-ml { + background-color: #0A7D91; + border-color: #0A7D91; + color: white; +} + +.btn-sacro-ml:hover { + background-color: #086a7a; + border-color: #086a7a; + color: white; +} + +.btn-acro-r { + background-color: #00843F; + border-color: #00843F; + color: white; +} + +.btn-acro-r:hover { + background-color: #006d35; + border-color: #006d35; + color: white; +} + +.btn-sacro-viewer { + background-color: #F66A0A; + border-color: #F66A0A; + color: white; +} + +.btn-sacro-viewer:hover { + background-color: #d4580a; + border-color: #d4580a; + color: white; +} diff --git a/pkgdown/extra.js b/pkgdown/extra.js new file mode 100644 index 0000000..8eac2f1 --- /dev/null +++ b/pkgdown/extra.js @@ -0,0 +1,28 @@ +document.addEventListener('DOMContentLoaded', function() { + const toggleButton = document.createElement('button'); + toggleButton.innerHTML = '🌙'; + toggleButton.className = 'lightswitch'; + toggleButton.setAttribute('aria-label', 'Toggle dark mode'); + + const navbar = document.querySelector('.navbar-nav'); + if (navbar) { + const li = document.createElement('li'); + li.className = 'nav-item'; + li.appendChild(toggleButton); + navbar.appendChild(li); + } + + toggleButton.addEventListener('click', function() { + const currentTheme = document.documentElement.getAttribute('data-bs-theme'); + const newTheme = currentTheme === 'dark' ? 'light' : 'dark'; + + document.documentElement.setAttribute('data-bs-theme', newTheme); + toggleButton.innerHTML = newTheme === 'dark' ? '☀️' : '🌙'; + + localStorage.setItem('theme', newTheme); + }); + + const savedTheme = localStorage.getItem('theme') || 'light'; + document.documentElement.setAttribute('data-bs-theme', savedTheme); + toggleButton.innerHTML = savedTheme === 'dark' ? '☀️' : '🌙'; +}); diff --git a/tests/testthat/test-acro_add_comments.R b/tests/testthat/test-acro_add_comments.R index d113bf9..d58550d 100644 --- a/tests/testthat/test-acro_add_comments.R +++ b/tests/testthat/test-acro_add_comments.R @@ -12,7 +12,7 @@ test_that("acro_add_comments works", { acro_finalise("test", "json") # Read the file content - file_content <- readLines(file.path("..", "testthat", "test", "results.json")) + file_content <- readLines(file.path("..", "testthat", "test", "results.json"), warn = FALSE) # Check the comment exists in the results expect_true(any(grepl(comment, file_content))) diff --git a/tests/testthat/test-acro_add_exception.R b/tests/testthat/test-acro_add_exception.R index 0feef42..9927bd9 100644 --- a/tests/testthat/test-acro_add_exception.R +++ b/tests/testthat/test-acro_add_exception.R @@ -11,7 +11,7 @@ test_that("add_exceptions works", { acro_finalise("test", "json") # Read the file content - file_content <- readLines(file.path("..", "testthat", "test", "results.json")) + file_content <- readLines(file.path("..", "testthat", "test", "results.json"), warn = FALSE) # Check the exception exists in the results expect_true(any(grepl("The disclosive cells are structural zeros and not actually disclosive", file_content))) }) diff --git a/tests/testthat/test-create_virtualenv.R b/tests/testthat/test-create_virtualenv.R new file mode 100644 index 0000000..c4ac98c --- /dev/null +++ b/tests/testthat/test-create_virtualenv.R @@ -0,0 +1,18 @@ +test_that("find_python returns a valid path", { + testthat::skip_on_cran() + python_path <- Sys.which("python3") + if (python_path == "") { + python_path <- Sys.which("python") + } + expect_true(python_path != "") +}) + +test_that("install_acro function exists and is callable", { + testthat::skip_on_cran() + expect_true(is.function(install_acro)) +}) + +test_that("create_virtualenv function exists and is callable", { + testthat::skip_on_cran() + expect_true(is.function(create_virtualenv)) +}) diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/example-notebook.Rmd b/vignettes/example-notebook.Rmd new file mode 100644 index 0000000..113ae6c --- /dev/null +++ b/vignettes/example-notebook.Rmd @@ -0,0 +1,19 @@ +--- +title: "example-notebook" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{example-notebook} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(acro) +```