mirror of
https://github.com/msberends/AMR.git
synced 2025-07-21 11:33:13 +02:00
(v2.1.1.9129) unit test fix
This commit is contained in:
@ -42,10 +42,6 @@ description_file="../DESCRIPTION"
|
||||
|
||||
# Write header to the datasets Python file, including the convert_to_python function
|
||||
cat <<EOL > "$datasets_file"
|
||||
BLUE = '\033[94m'
|
||||
GREEN = '\033[32m'
|
||||
RESET = '\033[0m'
|
||||
|
||||
import os
|
||||
import sys
|
||||
from rpy2 import robjects
|
||||
@ -61,18 +57,22 @@ venv_path = sys.prefix
|
||||
r_lib_path = os.path.join(venv_path, "R_libs")
|
||||
# Ensure the R library path exists
|
||||
os.makedirs(r_lib_path, exist_ok=True)
|
||||
# Set the R library path in .libPaths
|
||||
base = importr('base')
|
||||
# Turn off warnings
|
||||
base.options(warn = -1)
|
||||
|
||||
base._libPaths(r_lib_path)
|
||||
# Import base and utils
|
||||
base = importr('base')
|
||||
utils = importr('utils')
|
||||
|
||||
# Override R library paths globally for the session
|
||||
robjects.r(f'.Library <- "{r_lib_path}"') # Replace default library
|
||||
robjects.r(f'.Library.site <- "{r_lib_path}"') # Replace site-specific library
|
||||
base._libPaths(r_lib_path) # Override .libPaths() as well
|
||||
|
||||
# Get the effective library path
|
||||
r_amr_lib_path = base._libPaths()[0]
|
||||
|
||||
# Check if the AMR package is installed in R
|
||||
if not isinstalled('AMR', lib_loc = r_amr_lib_path):
|
||||
utils = importr('utils')
|
||||
print(f"{BLUE}AMR:{RESET} Installing AMR package to {BLUE}{r_amr_lib_path}/{RESET}...", flush=True)
|
||||
if not isinstalled('AMR', lib_loc=r_amr_lib_path):
|
||||
print(f"AMR: Installing latest AMR R package to {r_amr_lib_path}...", flush=True)
|
||||
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
|
||||
|
||||
# Python package version of AMR
|
||||
@ -87,16 +87,12 @@ r_amr_version = robjects.r(f'as.character(packageVersion("AMR", lib.loc = "{r_li
|
||||
# Compare R and Python package versions
|
||||
if r_amr_version != python_amr_version:
|
||||
try:
|
||||
print(f"{BLUE}AMR:{RESET} Updating AMR package in {BLUE}{r_amr_lib_path}/{RESET}...", flush=True)
|
||||
utils = importr('utils')
|
||||
print(f"AMR: Updating AMR package in {r_amr_lib_path}...", flush=True)
|
||||
utils.install_packages('AMR', repos='https://msberends.r-universe.dev', quiet=True)
|
||||
except Exception as e:
|
||||
print(f"{BLUE}AMR:{RESET} Could not update: {e}{RESET}", flush=True)
|
||||
print(f"AMR: Could not update: {e}", flush=True)
|
||||
|
||||
# Restore warnings to default
|
||||
base.options(warn = 0)
|
||||
|
||||
print(f"{BLUE}AMR:{RESET} Setting up R environment and AMR datasets...", flush=True)
|
||||
print(f"AMR: Setting up R environment and AMR datasets...", flush=True)
|
||||
|
||||
# Activate the automatic conversion between R and pandas DataFrames
|
||||
pandas2ri.activate()
|
||||
@ -121,7 +117,7 @@ microorganisms = pandas2ri.rpy2py(robjects.r('AMR::microorganisms[, !sapply(AMR:
|
||||
antibiotics = pandas2ri.rpy2py(robjects.r('AMR::antibiotics[, !sapply(AMR::antibiotics, is.list)]'))
|
||||
clinical_breakpoints = pandas2ri.rpy2py(robjects.r('AMR::clinical_breakpoints[, !sapply(AMR::clinical_breakpoints, is.list)]'))
|
||||
|
||||
print(f"{BLUE}AMR:{RESET} {GREEN}Done.{RESET}", flush=True)
|
||||
print(f"AMR: Done.", flush=True)
|
||||
EOL
|
||||
|
||||
echo "from .datasets import example_isolates" >> $init_file
|
||||
|
@ -1,5 +1,5 @@
|
||||
This files contains all context you must know about the AMR package for R.
|
||||
First and foremost, you are trained on version 2.1.1.9128. Remember this whenever someone asks which AMR package version you’re at.
|
||||
First and foremost, you are trained on version 2.1.1.9129. Remember this whenever someone asks which AMR package version you’re at.
|
||||
--------------------------------
|
||||
|
||||
THE PART HEREAFTER CONTAINS CONTENTS FROM FILE 'NAMESPACE':
|
||||
@ -1705,7 +1705,7 @@ This function returns a table with values between 0 and 100 for \emph{susceptibi
|
||||
|
||||
For estimating antimicrobial coverage, especially when creating a WISCA, the outcome might become more reliable by only including the top \emph{n} species encountered in the data. You can filter on this top \emph{n} using \code{\link[=top_n_microorganisms]{top_n_microorganisms()}}. For example, use \code{top_n_microorganisms(your_data, n = 10)} as a pre-processing step to only include the top 10 species in the data.
|
||||
|
||||
The numeric values of an antibiogram are stored in a long format as the \link{attribute} \code{long_numeric}. You can retrieve them using \code{attributes(x)$long_numeric}, where \code{x} is the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}. This is ideal for e.g. advanced plotting.
|
||||
The numeric values of an antibiogram are stored in a long format as the \link[=attributes]{attribute} \code{long_numeric}. You can retrieve them using \code{attributes(x)$long_numeric}, where \code{x} is the outcome of \code{\link[=antibiogram]{antibiogram()}} or \code{\link[=wisca]{wisca()}}. This is ideal for e.g. advanced plotting.
|
||||
\subsection{Formatting Type}{
|
||||
|
||||
The formatting of the 'cells' of the table can be set with the argument \code{formatting_type}. In these examples, \code{5} is the susceptibility percentage (for WISCA: \code{4-6} indicates the confidence level), \code{15} the numerator, and \code{300} the denominator:
|
||||
@ -3900,6 +3900,8 @@ bug_drug_combinations(x, col_mo = NULL, FUN = mo_shortname,
|
||||
|
||||
\item{FUN}{the function to call on the \code{mo} column to transform the microorganism codes - the default is \code{\link[=mo_shortname]{mo_shortname()}}}
|
||||
|
||||
\item{include_n_rows}{a \link{logical} to indicate if the total number of rows must be included in the output}
|
||||
|
||||
\item{...}{arguments passed on to \code{FUN}}
|
||||
|
||||
\item{translate_ab}{a \link{character} of length 1 containing column names of the \link{antibiotics} data set}
|
||||
@ -8027,7 +8029,7 @@ top_n_microorganisms(x, n, property = "fullname", n_for_each = NULL,
|
||||
This function filters a data set to include only the top \emph{n} microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera.
|
||||
}
|
||||
\details{
|
||||
This function is useful for preprocessing data before creating \link[=antibiograms]{antibiograms} or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species.
|
||||
This function is useful for preprocessing data before creating \link[=antibiogram]{antibiograms} or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species.
|
||||
}
|
||||
\examples{
|
||||
# filter to the top 3 species:
|
@ -2210,6 +2210,6 @@ devtools::load_all(".")
|
||||
|
||||
# run the unit tests
|
||||
Sys.setenv(NOT_CRAN = "true")
|
||||
testthat::test_file("inst/tinytest/test-data.R")
|
||||
testthat::test_file("inst/tinytest/test-mo.R")
|
||||
testthat::test_file("inst/tinytest/test-mo_property.R")
|
||||
testthat::test_file("inst/tests/testthat/test-data.R")
|
||||
testthat::test_file("inst/tests/testthat/test-mo.R")
|
||||
testthat::test_file("inst/tests/testthat/test-mo_property.R")
|
||||
|
Reference in New Issue
Block a user