diff --git a/DESCRIPTION b/DESCRIPTION index f4d231d948582695e2d232ba6ecff81ec9210475..3281fc9e0a342ba0490cae3e49cff3bb23435646 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,6 +48,7 @@ Collate: 'resources.R' 'errors.R' 'mix.R' + 'envopts.R' 'state.R' 'plotting.R' 'extraction.R' diff --git a/R/envopts.R b/R/envopts.R new file mode 100644 index 0000000000000000000000000000000000000000..e52961ce470caad759e4104f4f2cea084af14094 --- /dev/null +++ b/R/envopts.R @@ -0,0 +1,47 @@ +## Copyright (C) 2020,2021,2023 by University of Luxembourg + +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at + +## http://www.apache.org/licenses/LICENSE-2.0 + +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. + + +## Description +## +## This file contains functions which manipulate per-system and +## per-run parameters. For example, paths that may change from +## computer to computer, such as the location of the MetFrag JAR file. + + + + +#' @title Create a `envopts` Object +#' @details A `envopts` object is Shinyscreen way to store settings +#' related to a specific computing environment. Information such +#' as the run time path to a MetFrag JAR will vary from one to +#' another setup and we need to convey this to the `shinyscreen` +#' pipeline. +#' @param metfrag_db_dir `character(1)`, a path to the directory which contains MetFrag databases +#' @param metfrag_jar `character(1)`, a path to MetFrag JAR file +#' @return An `envopts` object. +#' @author Todor Kondić +envopts <- function(metfrag_db_dir="",metfrag_jar="") { + res = list(metfrag=list()) + class(res) = c("envopts","list") #Just to officially make it an + #object. + + check_dir_absent(metfrag_db_dir,what="mf-db-dir") + res$metfrag$db_dir = metfrag_db_dir + + check_file_absent(metfrag_jar,what="mf-jar") + res$metfrag$jar = metfrag_jar + + res +} diff --git a/R/errors.R b/R/errors.R index d3fe162dca8d7c6418c771b2baad5ef48748cbad..aa1a622637793ee8b4f8ca583bfb6eef33bb8e12 100644 --- a/R/errors.R +++ b/R/errors.R @@ -12,12 +12,18 @@ ## See the License for the specific language governing permissions and ## limitations under the License. -errc_mf_jar_absent = errorCondition("MetFrag jar file specified, but cannot be found.", class = "mf-jar-absent") -errc_mf_db_dir_absent = errorCondition("MetFrag DB directory specified, but cannot be found.", class = "mf-db-dir-absent") -errc_mf_db_file_absent = errorCondition("MetFrag DB file specified, but cannot be found.", class = "mf-db-dir-absent") +errc_conf_file_absent <- errorCondition("There is no config file in the project directory.",class="conf-file-absent") -errc_projects_absent = errorCondition("User root directory (projects), currently does not exist.. Abort.", class= "projects-absent") -errc_top_data_dir_absent = errorCondition("Data directory (top_data_dir) does not exist. Abort.", - class = "top-data-dir-absent") +check_notastring <- function(value,what) { + if (!is.character(value)) stop(errorCondition(paste0("The value (",str(value),") of, ",what," is not a character vector."),class=paste0(what,'-notastring'))) +} -errc_conf_file_absent <- errorCondition("There is no config file in the project directory.",class="conf-file-absent") +check_dir_absent <- function(dir,what) { + check_notastring(dir,what) + if (nchar(dir)>0L && !dir.exists(dir)) stop(errorCondition(paste0("The ", what, " directory --- ", dir, "--- does not exist, or cannot be found."), class=paste0(what,'-absent'))) +} + +check_file_absent <- function(file,what) { + check_notastring(file,what) + if (nchar(file)>0L && !file.exists(file)) stop(errorCondition(paste0("The ", what, " file --- ", file, "--- does not exist, or cannot be found."), class=paste0(what,'-absent'))) +} diff --git a/man/envopts.Rd b/man/envopts.Rd new file mode 100644 index 0000000000000000000000000000000000000000..027d62742a017148674115774c3b71ca8be84fac --- /dev/null +++ b/man/envopts.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/envopts.R +\name{envopts} +\alias{envopts} +\title{Create a \code{envopts} Object} +\usage{ +envopts(metfrag_db_dir = "", metfrag_jar = "") +} +\arguments{ +\item{metfrag_db_dir}{\code{character(1)}, a path to the directory which contains MetFrag databases} + +\item{metfrag_jar}{\code{character(1)}, a path to MetFrag JAR file} +} +\value{ +An \code{envopts} object. +} +\description{ +Create a \code{envopts} Object +} +\details{ +A \code{envopts} object is Shinyscreen way to store settings +related to a specific computing environment. Information such +as the run time path to a MetFrag JAR will vary from one to +another setup and we need to convey this to the \code{shinyscreen} +pipeline. +} +\author{ +Todor Kondić +}