Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
^docs/.*$
^.*\.o$
^.*\.a$
^\.github$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
62 changes: 62 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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:

name: R-CMD-check.yaml

permissions: read-all

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@v4

- 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

#- name: Build
# run: |
# R CMD build .

- uses: r-lib/actions/check-r-package@v2
with:
upload-results: true
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'

# - name: Upload test results
# uses: actions/upload-artifact@v4
# with:
# name: samplelim_${{ matrix.config.os }}
# path: samplelim*.tar.gz
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ Suggests:
GGally,
testthat (>= 3.0.0)
Config/testthat/edition: 3
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
VignetteBuilder: knitr
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(plot,lim)
export(Hpolytope)
export(df2lim)
export(full2red)
Expand All @@ -14,6 +15,8 @@ importFrom(Rcpp,evalCpp)
importFrom(Rcpp,loadModule)
importFrom(Rcpp,sourceCpp)
importFrom(Rglpk,Rglpk_solve_LP)
importFrom(igraph,graph_from_adjacency_matrix)
importFrom(igraph,plot.igraph)
importFrom(limSolve,lsei)
importFrom(methods,new)
importFrom(stats,cov)
Expand Down
37 changes: 25 additions & 12 deletions R/plot_lim.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
plot.lim <- function(lim, seed=NULL, ...) {
#' Plot a metabolic network
#'
##' @param x An object of class `lim` containing a component `Flowmatrix`.
#' @param seed The seed for the PRNG of the R session
#' @param ... Additionnal arguments to be passed to the function \code{plot.igraph()} from the package \code{\\{igraph\\}}.
#'
#' @return Returns NULL, invisibly.
#' @method plot lim
#'
#' @examples
#' DF <- system.file("extdata", "DeclarationFileBOWF-short.txt", package = "samplelim")
#' BOWF <- df2lim(DF)
#' plot(BOWF)
plot.lim <- function(x, seed=NULL, ...) {
# Check if 'Flowmatrix' exists in the object 'lim'
if (!exists("Flowmatrix", where = lim)) {
if (!exists("Flowmatrix", where = x)) {
stop("'Flowmatrix' does not exist in used 'lim' object.")
}

# Check if 'Flowmatrix' is a matrix
if (!is.matrix(lim$Flowmatrix)) {
if (!is.matrix(x$Flowmatrix)) {
stop("'Flowmatrix' from 'lim' object is not a matrix. ")
}

# Check if the dimensions of the matrix are equal to the expected dimensions
# As dimensions depends of NComponents and NExternal we first check if they exist and are integers
if (!exists("NComponents", where = lim)){
if (!exists("NComponents", where = x)){
stop("'NComponents' does not exist in used 'lim' object.")
}

if (!is.integer(lim$NComponents)){
if (!is.integer(x$NComponents)){
stop("'NComponents' from 'lim' object must be an integer.")
}

if (!exists("NExternal", where = lim)){
if (!exists("NExternal", where = x)){
stop("'NExternal' does not exist in used 'lim' object.")
}

if (!is.integer(lim$NExternal)){
if (!is.integer(x$NExternal)){
stop("'NExternal' from 'lim' object must be an integer.")
}

# Calculate the number of nodes
N_nodes <- lim$NComponents + lim$NExternal
N_nodes <- x$NComponents + x$NExternal

expected_dim <- c(N_nodes, N_nodes)
if (all(dim(lim$Flowmatrix) != expected_dim)) {
if (all(dim(x$Flowmatrix) != expected_dim)) {
stop("Flowmatrix from 'lim' object does not match the expected dimension.")
}

Expand All @@ -40,8 +53,8 @@ plot.lim <- function(lim, seed=NULL, ...) {
set.seed(seed)
}

adjacency_matrix <- as.matrix(lim$Flowmatrix > 0)
model_graph <- graph_from_adjacency_matrix(adjacency_matrix)
plot.igraph(model_graph, ...)
adjacency_matrix <- as.matrix(x$Flowmatrix > 0)
model_graph <- igraph::graph_from_adjacency_matrix(adjacency_matrix)
igraph::plot.igraph(model_graph, ...)

}
35 changes: 35 additions & 0 deletions R/samplelim.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' MCMC sampling algorithms for linear inverse models
#'
#' @description
#' The package provides efficient implementations (C++ encoded) of
#' Monte Carlo Markov Chains (MCMC) algorithms for uniformly sampling high-dimensional polytopes.
#' It is particularly aimed at handling linear inverse models (LIM) in metabolic
#' (trophic, biochemical or urban) networks.
#' Some support functions are also included to facilitate its use by practitioners.
#' @keywords
#' polytope
#' sampling
#' mcmc
#' lim
#' mirror-walk
#' billard-walk
#' trophic-network
#' urban-network
#' biochemical-network
#' metabolic-network
#' @references {
#' D. Van Oevelen, K. Van den Meersche, F. J. R. Meysman, K. Soetaert,
#' J. J. Middelburg and A. F. Vézina,
#' \emph{Quantifying Food Web Flows Using Linear Inverse Models},
#' Ecosystems \strong{13}, 32-45 (2010).
#'
#' B.T. Polyak and E.N. Gryazina,
#' \emph{Billiard walk - a new sampling algorithm for control and optimization},
#' IFAC Proceedings Volumes, \strong{47(3)}, 6123-6128 (2014).
#'
#' V. Girardin, T. Grente, N. Niquil and P. Regnault,
#' \emph{Comparing and updating R packages of MCMC Algorithms for
#' Linear Inverse Modeling of Metabolic Networks}, to appear in
#' Communications in Statistics - Simulation and Computation (2025)
#' }
"_PACKAGE"
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ knitr::opts_chunk$set(echo = TRUE, eval = TRUE)
![](https://img.shields.io/badge/lifecycle-maturing-blue.svg)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
[![R-CMD-check](https://github.com/pregnault/samplelim/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pregnault/samplelim/actions/workflows/R-CMD-check.yaml)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/regexplain)](https://cran.r-project.org/package=samplelim)

The package `{samplelim}` for the R statistical software provides efficient implementations (C++ encoded) of Monte Carlo Markov Chains (MCMC) algorithms for uniformly sampling high-dimensional polytopes.
Expand Down
26 changes: 26 additions & 0 deletions man/plot.lim.Rd

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

81 changes: 57 additions & 24 deletions man/samplelim-package.Rd
100755 → 100644

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

Loading