read_write.R 9.42 KiB
# \\\
# Copyright 2021-2022 Louis Héraut*1,
#                     Éric Sauquet*2,
#                     Valentin Mansanarez
# *1   INRAE, France
#      louis.heraut@inrae.fr
# *2   INRAE, France
#      eric.sauquet@inrae.fr
# This file is part of ash R toolbox.
# Ash R toolbox is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# Ash R toolbox is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with ash R toolbox.
# If not, see <https://www.gnu.org/licenses/>.
# ///
# Rcode/processing/results_manager.R
# Manages the writing and reading of results data of the trend analysis.
## 1. WRITING ________________________________________________________
### 1.1. List of dataframe ___________________________________________
write_analyse = function (Ldf, resdir, filedir) {
    outdir = file.path(resdir, filedir)
    if (!(file.exists(outdir))) {
        dir.create(outdir, recursive=TRUE)
    print(paste('Writing of list of dataframe in : ', outdir, sep=''))
    Lname = names(Ldf)
    Nname = length(Lname)
    for (i in 1:Nname) {
        outfile = paste(Lname[i], '.txt', sep='')
        write.table(Ldf[[i]],
                    file=file.path(outdir, outfile),
                    sep=";",
                    quote=TRUE,
                    row.names=FALSE)
### 1.2. Dataframe of modified data __________________________________
write_data = function (df_data, df_mod, resdir, filedir) {
    Code = rle(sort(df_mod$code))$values
    outdir = file.path(resdir, filedir)
    if (!(file.exists(outdir))) {
        dir.create(outdir, recursive=TRUE)
    print(paste('Writing of modified data in : ', outdir, sep=''))
    for (code in Code) {