Title: | An Interface Between the 'FSKX' Standard and 'R' |
---|---|
Description: | Functions for importing, creating, editing and exporting 'FSK' files <https://foodrisklabs.bfr.bund.de/fskx-food-safety-knowledge-exchange-format/> using the 'R' programming environment. Furthermore, it enables users to run simulations contained in the 'FSK' files and visualize the results. |
Authors: | Alberto Garre [aut, cre], Miguel de Alba Aparicio [aut], Pablo S. Fernandez [aut], Matthias Filter [aut] |
Maintainer: | Alberto Garre <[email protected]> |
License: | GPL-3 |
Version: | 0.1.3 |
Built: | 2024-10-29 04:17:33 UTC |
Source: | https://github.com/cran/FSK2R |
Checks that the files defined in the manifest exist
check_manifest_files(my_manifest, file_dir)
check_manifest_files(my_manifest, file_dir)
my_manifest |
A list with the contents of the manifest file. |
file_dir |
Path to the directory where all the files have been extracted. |
Fix the metadat so that it is lists
convert_metadata_to_lists(my_metadata)
convert_metadata_to_lists(my_metadata)
my_metadata |
A list with the information in the GoogleSheet as generated by metadata_list_to_fsk. |
The model includes the R model. If provided as arguments, it also includes the visualization script and the README. Besides, it generates a typical model_metadata, as well as a simulation (without parameters). The manifest is left empty.
create_fsk( r_model, r_visualization = NULL, readme = NULL, other_files = NULL, pckg_frame = NULL )
create_fsk( r_model, r_visualization = NULL, readme = NULL, other_files = NULL, pckg_frame = NULL )
r_model |
character with the path to the R script with the model. |
r_visualization |
(optional) character with the path to the R script with the visualization. |
readme |
(optional) path to README file. |
other_files |
(optional) character vector with the path to additional |
pckg_frame |
(optional) data.frame with 2 columns 'Package' files required by the model. |
An instance of FSK2R.
model_path <- system.file("extdata", "model.r", package = "FSK2R") visualization_path <- system.file("extdata", "visualization.r", package = "FSK2R") FSK_from_R <- create_fsk(model_path, visualization_path)
model_path <- system.file("extdata", "model.r", package = "FSK2R") visualization_path <- system.file("extdata", "visualization.r", package = "FSK2R") FSK_from_R <- create_fsk(model_path, visualization_path)
This function is needed to convert the output format of rjson to the one used by FSK2R.
dataframe_to_list(this_frame)
dataframe_to_list(this_frame)
this_frame |
data.frame to convert to a list. |
Exports an object of FSK class as an .fskx file
export_fsk(fsk_object, out_path, check = TRUE)
export_fsk(fsk_object, out_path, check = TRUE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
None
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) class(my_fsk) export_fsk(my_fsk, out_path=file.path(tempdir(), "out.fskx"))
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) class(my_fsk) export_fsk(my_fsk, out_path=file.path(tempdir(), "out.fskx"))
Functions for exporting the manifest of an FSK2R object
export_manifest(fsk_object, out_path, check = FALSE)
export_manifest(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Function for exporting the metadata of an FSK2R object
export_metadata(fsk_object, out_path, check = FALSE)
export_metadata(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Functions for exporting the model metadata of an FSK2R object
export_modelmetadata(fsk_object, out_path, check = FALSE)
export_modelmetadata(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Export other files
export_otherfiles(fsk_object, out_path, check = FALSE)
export_otherfiles(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Functions for exporting the packages of an FSK2R object
export_packages(fsk_object, out_path, check = FALSE)
export_packages(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Functions for exporting the R model of an FSK2R object
export_R_model(fsk_object, out_path, check = FALSE)
export_R_model(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Functions for exporting the README of an FSK2R object
export_readme(fsk_object, out_path, check = FALSE)
export_readme(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Export the model.sbml
export_sbmlModel(fsk_object, out_path, check = FALSE)
export_sbmlModel(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Export the sim.sedml
export_simulation(fsk_object, out_path, check = FALSE)
export_simulation(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Functions for exporting the visualization script of an FSK2R object
export_visualization(fsk_object, out_path, check = FALSE)
export_visualization(fsk_object, out_path, check = FALSE)
fsk_object |
The instance of FSK2R to be exported. |
out_path |
Path where the file is to be saved. |
check |
Whether checks are made. TRUE by default. |
Finds where packages are stored
find_packages(pckgs)
find_packages(pckgs)
pckgs |
Character vector with packages names |
A list of packages locations. If one is not present, a character(0).
Starts FSK runner within RStudio.
FSK_runner()
FSK_runner()
None
Returns the background of an FSK object
get_background(fsk_obj)
get_background(fsk_obj)
fsk_obj |
An object of class FSK2R |
A nested list with the following entries:
studyTitle
studyDescription
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_background(my_fsk)
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_background(my_fsk)
Returns the general info of an FSK object
get_general_info(fsk_obj)
get_general_info(fsk_obj)
fsk_obj |
An object of class FSK2R |
A nested list with the following entries:
name
source
identifier
creationDate
rights
language
software
creators
reference
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_general_info(my_fsk)
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_general_info(my_fsk)
Returns the model math of an FSK object
get_modelmath(fsk_obj)
get_modelmath(fsk_obj)
fsk_obj |
An object of class FSK2R |
A nested list with the following entries:
parameter
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_modelmath(my_fsk)
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_modelmath(my_fsk)
Readme of an FSK object
get_readme(fsk_obj)
get_readme(fsk_obj)
fsk_obj |
An object of class FSK2R |
A character vector with the text in the README file.
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_readme(my_fsk)
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_readme(my_fsk)
Returns the scope of an FSK object
get_scope(fsk_obj)
get_scope(fsk_obj)
fsk_obj |
An object of class FSK2R |
A nested list with the following entries:
product
hazard
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_scope(my_fsk)
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_scope(my_fsk)
Extract session information
get_session_info()
get_session_info()
A list with 3 elements: r_version, platform and pckgs. The latter is a data.frame with two columns: package and version.
The function is not in-use. It is kept here for compatibility with older versions.
get_simulations(fsk_obj)
get_simulations(fsk_obj)
fsk_obj |
An object of class FSK2R |
Importst the file in file_path and transforms it into a list of class FSK2R.
import_fsk(file_path, check = FALSE)
import_fsk(file_path, check = FALSE)
file_path |
Path where the file is located. |
check |
Whether checks are made. FALSE by default. |
An instance of FSK2R.
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_general_info(my_fsk)
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) get_general_info(my_fsk)
Join nodes are not yet supported by FSK2R. It just gives an error message when called.
import_fsk_join(file_path, check = TRUE)
import_fsk_join(file_path, check = TRUE)
file_path |
Path where the file is located. |
check |
Whether checks are made. FALSE by default. |
Does the object have an R model?
is_fsk_with_r(fsk_obj)
is_fsk_with_r(fsk_obj)
fsk_obj |
An object of class FSK2R |
A logical vector.
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) is_fsk_with_r(my_fsk)
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) is_fsk_with_r(my_fsk)
Is it an instance of FSK2R?
is.FSK2R(object)
is.FSK2R(object)
object |
Object to check |
A logical vector
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) is.FSK2R(my_fsk)
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) is.FSK2R(my_fsk)
Maps the location (range) of different pieces of data within the Excel/Google Sheets template. It also includes the names of the sheets.
map_FSK_metadata(type_of_model = "generic", fsk_version = "1.04")
map_FSK_metadata(type_of_model = "generic", fsk_version = "1.04")
type_of_model |
Type of model, as defined in the FSK-ML documentation. By default, 'generic'. |
fsk_version |
Character stating the version of FSK-ML. |
A list with two components: the 'range' where each piece of information is stored and 'ws_name' with the name of the relevant sheet in the GoogleSheet template.
Returns a map of the names used within the sheets of the Excel/GoogleSheets template and the ones in metadata.json.
map_metadata_xml_template()
map_metadata_xml_template()
Converts the contents of the Excel/Google Sheets template into a list with the format of the FSK2R object.
metadata_list_to_fsk(my_metadata, fsk_version = "1.0.5")
metadata_list_to_fsk(my_metadata, fsk_version = "1.0.5")
my_metadata |
A list generated by |
fsk_version |
Version of the FSK template. |
Number of simulations in the FSK2R object
n_simuls_fsk(fsk_obj)
n_simuls_fsk(fsk_obj)
fsk_obj |
An instance of FSK2R |
An integer vector of length one.
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) n_simuls_fsk(my_fsk)
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) n_simuls_fsk(my_fsk)
Read the metadata.json file
read_fsk_json_metadata(file_dir, check = FALSE, filename = "metaData.json")
read_fsk_json_metadata(file_dir, check = FALSE, filename = "metaData.json")
file_dir |
path to the file. |
check |
Whether to make checks. FALSE by default. |
filename |
Name of the file whith the information (meataData.json by default). |
A list with the contents of the metadata file.
Read the manifest of an FSK file and convert it to a data.frame
read_fsk_manifest(file_dir, check = FALSE, filename = "manifest.xml")
read_fsk_manifest(file_dir, check = FALSE, filename = "manifest.xml")
file_dir |
path to the file. |
check |
Whether to make checks. FALSE by default. |
filename |
Name of the file whith the information (manifest.xml by default). |
A data.frame with the contents of the xlm file.
FSK metadata from local Excel file
read_fsk_metadata_excel( fsk_object, path, type_of_model = "generic", fsk_version = "1.0.5" )
read_fsk_metadata_excel( fsk_object, path, type_of_model = "generic", fsk_version = "1.0.5" )
fsk_object |
FSK2R object where to save the data |
path |
character describing the path to the file |
type_of_model |
character identifying the type of model |
fsk_version |
Character describing the version of FSK-ML ("1.04" by default). |
A list with the information in the Excel file as generated by metadata_list_to_fsk.
Read the model.sbml
read_fsk_model(file_dir, check = FALSE, filename = "model.sbml")
read_fsk_model(file_dir, check = FALSE, filename = "model.sbml")
file_dir |
path to the file. |
check |
Whether to make checks. FALSE by default. |
filename |
Name of the file whith the information (model.sbml by default). |
A list with the contents of the .xml file.
Read the packages.json
read_fsk_packages(file_dir, check = FALSE, filename = "packages.json")
read_fsk_packages(file_dir, check = FALSE, filename = "packages.json")
file_dir |
path to the file. |
check |
Whether to make checks. FALSE by default. |
filename |
Name of the file whith the information (packages.json by default). |
A list with the contents of the JSON file.
Read the metadata.rdf
read_fsk_rdf_metadata(file_dir, check = FALSE, filename = "metadata.rdf")
read_fsk_rdf_metadata(file_dir, check = FALSE, filename = "metadata.rdf")
file_dir |
path to the file. |
check |
Whether to make checks. FALSE by default. |
filename |
Name of the file whith the information (metadata.rdf by default). |
A list with the contents of the .xml file.
Read the README file
read_fsk_readme(file_dir, check = FALSE, filename = "README.txt")
read_fsk_readme(file_dir, check = FALSE, filename = "README.txt")
file_dir |
path to the file. |
check |
Whether to make checks. FALSE by default. |
filename |
Name of the file whith the information (README.txt by default). |
A character string with the content of the README file.
Read the sim.sedml file
read_fsk_sim(file_dir, check = FALSE, filename = "sim.sedml")
read_fsk_sim(file_dir, check = FALSE, filename = "sim.sedml")
file_dir |
path to the file. |
check |
Whether to make checks. FALSE by default. |
filename |
Name of the file whith the information (sim.sedml by default). |
A list with the content of the xml file.
The R models may require further files that we can not predict. This functions just reads all the "unrecognized" files included in the manifest and copies them to the working directory.
read_other_files(my_tempdir, my_manifest, check = FALSE)
read_other_files(my_tempdir, my_manifest, check = FALSE)
my_tempdir |
Temporary directory to extract contents of the zyp file. |
my_manifest |
A list with the information in the manifest file |
check |
Whether checks are made. |
Reads the R model in an FSK model
read_R_model(file_dir, check = FALSE, filename = "model.R")
read_R_model(file_dir, check = FALSE, filename = "model.R")
file_dir |
path to the file. |
check |
Whether to make checks. FALSE by default. |
filename |
Name of the file (model.R by default). |
A character string with the contents of the R file.
Reads the visualization script in an FSK model
read_visualization(file_dir, check = FALSE, filename = "visualization.R")
read_visualization(file_dir, check = FALSE, filename = "visualization.R")
file_dir |
path to the file. |
check |
Whether to make checks. FALSE by default. |
filename |
Name of the file whith the information (visualization.R by default). |
A character string with the contents of the R file.
Runs every simulation defined in the FSK object. This includes the ones originally included in the FSK container, as well as the ones added using set_new_simulation().
run_all_simulations(fsk_object, run_visualization = FALSE)
run_all_simulations(fsk_object, run_visualization = FALSE)
fsk_object |
Instance of FSK2R |
run_visualization |
Whether to call the visualization script. FALSE by default. |
None
Runs the simulation corresponding to index. If defined, it also calls any visualization script.
run_simulation(fsk_object, index, run_visualization = FALSE)
run_simulation(fsk_object, index, run_visualization = FALSE)
fsk_object |
Instance of FSK2R |
index |
Index of the simulation |
run_visualization |
Whether to call the visualization script. FALSE by default. |
None
Sets a new simulation using the parameters defined in simulation_pars. The method updates all the relevant methods.
set_new_simulation(fsk_object, simulation_id, parameters)
set_new_simulation(fsk_object, simulation_id, parameters)
fsk_object |
Instance of FSK2R |
simulation_id |
A character with an id for the new simulation. |
parameters |
A list whose names are the parameters to modify and their values their values for the simulation. |
An instance of FSK2R with the additional simulation data.
Readme of an FSK object
set_readme(fsk_object, readme_text)
set_readme(fsk_object, readme_text)
fsk_object |
An instance of FSK2R. |
readme_text |
A character vector of length 1 with the content of the README file. |
An instance of FSK2R.
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) set_readme(my_fsk, "This is the README.")
path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R") my_fsk <- import_fsk(path_example) set_readme(my_fsk, "This is the README.")
Updates the manifest file
update_manifest(fsk_object)
update_manifest(fsk_object)
fsk_object |
An instance of FSK2R. |