Package 'FSK2R'

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

Help Index


Checks that the files defined in the manifest exist

Description

Checks that the files defined in the manifest exist

Usage

check_manifest_files(my_manifest, file_dir)

Arguments

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

Description

Fix the metadat so that it is lists

Usage

convert_metadata_to_lists(my_metadata)

Arguments

my_metadata

A list with the information in the GoogleSheet as generated by metadata_list_to_fsk.


Creates an FSK model from an existing R script

Description

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.

Usage

create_fsk(
  r_model,
  r_visualization = NULL,
  readme = NULL,
  other_files = NULL,
  pckg_frame = NULL
)

Arguments

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.

Value

An instance of FSK2R.

Examples

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)

Converts a dataframe to a list

Description

This function is needed to convert the output format of rjson to the one used by FSK2R.

Usage

dataframe_to_list(this_frame)

Arguments

this_frame

data.frame to convert to a list.


Exports an object of FSK class as an .fskx file

Description

Exports an object of FSK class as an .fskx file

Usage

export_fsk(fsk_object, out_path, check = TRUE)

Arguments

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.

Value

None

Examples

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

Description

Functions for exporting the manifest of an FSK2R object

Usage

export_manifest(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Function for exporting the metadata of an FSK2R object

Usage

export_metadata(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Functions for exporting the model metadata of an FSK2R object

Usage

export_modelmetadata(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Export other files

Usage

export_otherfiles(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Functions for exporting the packages of an FSK2R object

Usage

export_packages(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Functions for exporting the R model of an FSK2R object

Usage

export_R_model(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Functions for exporting the README of an FSK2R object

Usage

export_readme(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Export the model.sbml

Usage

export_sbmlModel(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Export the sim.sedml

Usage

export_simulation(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Functions for exporting the visualization script of an FSK2R object

Usage

export_visualization(fsk_object, out_path, check = FALSE)

Arguments

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

Description

Finds where packages are stored

Usage

find_packages(pckgs)

Arguments

pckgs

Character vector with packages names

Value

A list of packages locations. If one is not present, a character(0).


Startup FSK runner

Description

Starts FSK runner within RStudio.

Usage

FSK_runner()

Value

None


Returns the background of an FSK object

Description

Returns the background of an FSK object

Usage

get_background(fsk_obj)

Arguments

fsk_obj

An object of class FSK2R

Value

A nested list with the following entries:

  • studyTitle

  • studyDescription

Examples

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

Description

Returns the general info of an FSK object

Usage

get_general_info(fsk_obj)

Arguments

fsk_obj

An object of class FSK2R

Value

A nested list with the following entries:

  • name

  • source

  • identifier

  • creationDate

  • rights

  • language

  • software

  • creators

  • reference

Examples

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

Description

Returns the model math of an FSK object

Usage

get_modelmath(fsk_obj)

Arguments

fsk_obj

An object of class FSK2R

Value

A nested list with the following entries:

  • parameter

Examples

path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R")
 my_fsk <- import_fsk(path_example)
 get_modelmath(my_fsk)

Readme of an FSK object

Description

Readme of an FSK object

Usage

get_readme(fsk_obj)

Arguments

fsk_obj

An object of class FSK2R

Value

A character vector with the text in the README file.

Examples

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

Description

Returns the scope of an FSK object

Usage

get_scope(fsk_obj)

Arguments

fsk_obj

An object of class FSK2R

Value

A nested list with the following entries:

  • product

  • hazard

Examples

path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R")
 my_fsk <- import_fsk(path_example)
 get_scope(my_fsk)

Extract session information

Description

Extract session information

Usage

get_session_info()

Value

A list with 3 elements: r_version, platform and pckgs. The latter is a data.frame with two columns: package and version.


Returns a summary of the simulations of an FSK object (NULL)

Description

The function is not in-use. It is kept here for compatibility with older versions.

Usage

get_simulations(fsk_obj)

Arguments

fsk_obj

An object of class FSK2R


Import an FSK model into R

Description

Importst the file in file_path and transforms it into a list of class FSK2R.

Usage

import_fsk(file_path, check = FALSE)

Arguments

file_path

Path where the file is located.

check

Whether checks are made. FALSE by default.

Value

An instance of FSK2R.

Examples

path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R")
 my_fsk <- import_fsk(path_example)
 get_general_info(my_fsk)

Import of FSK with join node

Description

Join nodes are not yet supported by FSK2R. It just gives an error message when called.

Usage

import_fsk_join(file_path, check = TRUE)

Arguments

file_path

Path where the file is located.

check

Whether checks are made. FALSE by default.


Does the object have an R model?

Description

Does the object have an R model?

Usage

is_fsk_with_r(fsk_obj)

Arguments

fsk_obj

An object of class FSK2R

Value

A logical vector.

Examples

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?

Description

Is it an instance of FSK2R?

Usage

is.FSK2R(object)

Arguments

object

Object to check

Value

A logical vector

Examples

path_example <- system.file("extdata", "ToyModelv4.fskx", package = "FSK2R")
 my_fsk <- import_fsk(path_example)
 is.FSK2R(my_fsk)

Map for the contents of the metadata

Description

Maps the location (range) of different pieces of data within the Excel/Google Sheets template. It also includes the names of the sheets.

Usage

map_FSK_metadata(type_of_model = "generic", fsk_version = "1.04")

Arguments

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.

Value

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.


Map between the names used in the template and the xml

Description

Returns a map of the names used within the sheets of the Excel/GoogleSheets template and the ones in metadata.json.

Usage

map_metadata_xml_template()

From read_fsk_metadata_XX to FSK2R format

Description

Converts the contents of the Excel/Google Sheets template into a list with the format of the FSK2R object.

Usage

metadata_list_to_fsk(my_metadata, fsk_version = "1.0.5")

Arguments

my_metadata

A list generated by

fsk_version

Version of the FSK template.


Number of simulations in the FSK2R object

Description

Number of simulations in the FSK2R object

Usage

n_simuls_fsk(fsk_obj)

Arguments

fsk_obj

An instance of FSK2R

Value

An integer vector of length one.

Examples

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

Description

Read the metadata.json file

Usage

read_fsk_json_metadata(file_dir, check = FALSE, filename = "metaData.json")

Arguments

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).

Value

A list with the contents of the metadata file.


Read the manifest of an FSK file and convert it to a data.frame

Description

Read the manifest of an FSK file and convert it to a data.frame

Usage

read_fsk_manifest(file_dir, check = FALSE, filename = "manifest.xml")

Arguments

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).

Value

A data.frame with the contents of the xlm file.


FSK metadata from local Excel file

Description

FSK metadata from local Excel file

Usage

read_fsk_metadata_excel(
  fsk_object,
  path,
  type_of_model = "generic",
  fsk_version = "1.0.5"
)

Arguments

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).

Value

A list with the information in the Excel file as generated by metadata_list_to_fsk.


Read the model.sbml

Description

Read the model.sbml

Usage

read_fsk_model(file_dir, check = FALSE, filename = "model.sbml")

Arguments

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).

Value

A list with the contents of the .xml file.


Read the packages.json

Description

Read the packages.json

Usage

read_fsk_packages(file_dir, check = FALSE, filename = "packages.json")

Arguments

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).

Value

A list with the contents of the JSON file.


Read the metadata.rdf

Description

Read the metadata.rdf

Usage

read_fsk_rdf_metadata(file_dir, check = FALSE, filename = "metadata.rdf")

Arguments

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).

Value

A list with the contents of the .xml file.


Read the README file

Description

Read the README file

Usage

read_fsk_readme(file_dir, check = FALSE, filename = "README.txt")

Arguments

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).

Value

A character string with the content of the README file.


Read the sim.sedml file

Description

Read the sim.sedml file

Usage

read_fsk_sim(file_dir, check = FALSE, filename = "sim.sedml")

Arguments

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).

Value

A list with the content of the xml file.


Read "other files"

Description

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.

Usage

read_other_files(my_tempdir, my_manifest, check = FALSE)

Arguments

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

Description

Reads the R model in an FSK model

Usage

read_R_model(file_dir, check = FALSE, filename = "model.R")

Arguments

file_dir

path to the file.

check

Whether to make checks. FALSE by default.

filename

Name of the file (model.R by default).

Value

A character string with the contents of the R file.


Reads the visualization script in an FSK model

Description

Reads the visualization script in an FSK model

Usage

read_visualization(file_dir, check = FALSE, filename = "visualization.R")

Arguments

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).

Value

A character string with the contents of the R file.


Run every simulation in an FSK object

Description

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().

Usage

run_all_simulations(fsk_object, run_visualization = FALSE)

Arguments

fsk_object

Instance of FSK2R

run_visualization

Whether to call the visualization script. FALSE by default.

Value

None


Run one simulation in an FSK object

Description

Runs the simulation corresponding to index. If defined, it also calls any visualization script.

Usage

run_simulation(fsk_object, index, run_visualization = FALSE)

Arguments

fsk_object

Instance of FSK2R

index

Index of the simulation

run_visualization

Whether to call the visualization script. FALSE by default.

Value

None


Define a new simulation in an FSK2R object

Description

Sets a new simulation using the parameters defined in simulation_pars. The method updates all the relevant methods.

Usage

set_new_simulation(fsk_object, simulation_id, parameters)

Arguments

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.

Value

An instance of FSK2R with the additional simulation data.


Readme of an FSK object

Description

Readme of an FSK object

Usage

set_readme(fsk_object, readme_text)

Arguments

fsk_object

An instance of FSK2R.

readme_text

A character vector of length 1 with the content of the README file.

Value

An instance of FSK2R.

Examples

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

Description

Updates the manifest file

Usage

update_manifest(fsk_object)

Arguments

fsk_object

An instance of FSK2R.