Skip to content
Snippets Groups Projects
README.md 8.63 KiB
Newer Older

<!-- README.md is generated from README.Rmd. Please edit that file -->

Dorch's avatar
Dorch committed
# fairify: an R package for creating FAIR reports
David Dorchies's avatar
David Dorchies committed

<img src="man/figures/logo.png" align="right" style="float: right; height: 220px; margin: 15px;"/>

FAIR principles stands for **F**indability, **A**ccessibility,
**I**nteroperability, and **R**euse.
David Dorchies's avatar
David Dorchies committed

David Dorchies's avatar
David Dorchies committed
This package provide tools to help you to create HTML and PDF reports
based on [bookdown](https://pkgs.rstudio.com/bookdown/) with data stored
on the cloud.
David Dorchies's avatar
David Dorchies committed

**fairify** currently supports data access Owncloud/Nextcloud servers
and provides templates for Inrae website and PDF reports.
David Dorchies's avatar
David Dorchies committed

Dorch's avatar
Dorch committed
## Installation
David Dorchies's avatar
David Dorchies committed

``` r
Dorch's avatar
Dorch committed
# install.packages("remotes")
remotes::install_git(
  "https://forgemia.inra.fr/umr-g-eau/fairify.git",
Dorch's avatar
Dorch committed
  dependencies = TRUE
)
David Dorchies's avatar
David Dorchies committed
```

## Create a *fairify* project

`create_fairify` creates a R-package skeleton and open your *fairify*
project on Rstudio:

    # Create a project in a temporary folder for the example
    path <- file.path(tempdir(), "my_fairify_project")
    fairify::create_fairify(path)

David Dorchies's avatar
David Dorchies committed
    ## ✔ Creating 'C:/Users/DDORCH~1/AppData/Local/Temp/RtmpsJQiJu/my_fairify_project/'
    ## ✔ Setting active project to 'C:/Users/ddorchies/AppData/Local/Temp/RtmpsJQiJu/my_fairify_project'
    ## ✔ Creating 'R/'
    ## ✔ Writing 'DESCRIPTION'

    ## Package: my_fairify_project
    ## Title: What the Package Does (One Line, Title Case)
    ## Version: 0.0.0.9000
    ## Authors@R (parsed):
    ##     * First Last <first.last@example.com> [aut, cre] (YOUR-ORCID-ID)
    ## Description: What the package does (one paragraph).
    ## License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
    ##     license
    ## Remotes:
    ##     git::https://forgemia.inra.fr/umr-g-eau/fairify.git
    ## Encoding: UTF-8
    ## Roxygen: list(markdown = TRUE)
    ## RoxygenNote: 7.3.1

    ## ✔ Writing 'NAMESPACE'
    ## ✔ Setting active project to '<no active project>'
David Dorchies's avatar
David Dorchies committed
    ## ✔ Setting active project to 'C:/Users/ddorchies/AppData/Local/Temp/RtmpsJQiJu/my_fairify_project'
    ## ✔ Adding 'fairify' to Depends field in DESCRIPTION
    ## • Are you sure you want Depends? Imports is almost always the better choice.
David Dorchies's avatar
David Dorchies committed
    ## ✔ Setting active project to 'C:/Users/ddorchies/AppData/Local/Temp/RtmpsJQiJu/my_fairify_project'
    ## ✔ Adding '^_pkgdown\\.yml$', '^public$', '^pkgdown$' to '.Rbuildignore'
    ## ✔ Adding 'public' to '.gitignore'
    ## Fairify project created
    ## 
    ## Don't forget to edit the file `inst/config.yml` for configuring the data location for your project
    ## 
David Dorchies's avatar
David Dorchies committed
    ## ✔ Setting active project to 'C:/Users/ddorchies/AppData/Local/Temp/RtmpsJQiJu/my_fairify_project'

    list.files(path)

    ## [1] "_pkgdown.yml" "DESCRIPTION"  "inst"         "NAMESPACE"    "R"           
    ## [6] "reports"      "templates"
David Dorchies's avatar
David Dorchies committed

## Create reports with **bookdown**
David Dorchies's avatar
David Dorchies committed

By default, the *fairify* project contains a `reports` folder which will
contain bookdown reports.
David Dorchies's avatar
David Dorchies committed

Use the function `fairify::add_report` for creating a new report.
David Dorchies's avatar
David Dorchies committed

    # Create a report
    fairify::add_report("my_report", template = "umr_geau", path = path)
David Dorchies's avatar
David Dorchies committed
    ## [1] "C:\\Users\\DDORCH~1\\AppData\\Local\\Temp\\RtmpsJQiJu/my_fairify_project/reports/my_report"

    # Add a chapter
    writeLines(
      c(
        "# A new chapter",
        "",
        "With a new paragraph."
      ),
      file.path(path, "reports/my_report/01-new_chapter.Rmd")
    )

Read the [documentation of
bookdown](https://bookdown.org/yihui/bookdown/) for more details on how
to write great reports with references, figures, and formulas.

The template parameter allows to choose the LaTeX template used for
rendering the PDF report. The LaTeX template settings can be overloaded
David Dorchies's avatar
David Dorchies committed
by modifying the files “`in_header.tex`”, “`before_body.tex`”, and
`after_body.tex`” located in the report folder ([See bookdown
documentation for
details](https://bookdown.org/yihui/bookdown/yaml-options.html)).

## Render reports

By default, the reports are rendered in the public folder of the
*fairify* project.

    # Render the report in HTML format
    fairify::render_reports(reports_dir = file.path(path, "reports"))

    ## folder list:

    ## my_report

    ## *******************************************************************

    ## ** RENDER my_report

    ## *******************************************************************

    ## output_format=bookdown::gitbook

David Dorchies's avatar
David Dorchies committed
    ## Rendering book in directory 'C:\Users\DDORCH~1\AppData\Local\Temp\RtmpsJQiJu/my_fairify_project/reports/my_report'
David Dorchies's avatar
David Dorchies committed

    ## processing file: report.Rmd
David Dorchies's avatar
David Dorchies committed

    ## output file: report.knit.md
David Dorchies's avatar
David Dorchies committed

David Dorchies's avatar
David Dorchies committed
    ## "C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS report.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output report.html --lua-filter "C:\Users\ddorchies\AppData\Local\Programs\R\R-4.3.1\library\bookdown\rmarkdown\lua\custom-environment.lua" --lua-filter "C:\Users\ddorchies\AppData\Local\Programs\R\R-4.3.1\library\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\ddorchies\AppData\Local\Programs\R\R-4.3.1\library\rmarkdown\rmarkdown\lua\latex-div.lua" --lua-filter "C:\Users\ddorchies\AppData\Local\Programs\R\R-4.3.1\library\rmarkdown\rmarkdown\lua\anchor-sections.lua" --metadata-file "C:\Users\DDORCH~1\AppData\Local\Temp\RtmpsJQiJu\file5664ef05c75" --wrap preserve --standalone --section-divs --table-of-contents --toc-depth 3 --template "C:\Users\ddorchies\AppData\Local\Programs\R\R-4.3.1\library\bookdown\templates\gitbook.html" --highlight-style pygments --number-sections --css style.css --mathjax --include-in-header "C:\Users\DDORCH~1\AppData\Local\Temp\RtmpsJQiJu\rmarkdown-str56644c4a78c5.html" --citeproc
David Dorchies's avatar
David Dorchies committed
    ## Output created: C:/Users/DDORCH~1/AppData/Local/Temp/RtmpsJQiJu/my_fairify_project/public/reports/my_report/index.html

    # Render the report in PDF format
    fairify::render_reports(reports_dir = file.path(path, "reports"),
                   output_format = "bookdown::pdf_book")

    ## folder list:

    ## my_report

    ## *******************************************************************

    ## ** RENDER my_report

    ## *******************************************************************

    ## output_format=bookdown::pdf_book

David Dorchies's avatar
David Dorchies committed
    ## Rendering book in directory 'C:\Users\DDORCH~1\AppData\Local\Temp\RtmpsJQiJu/my_fairify_project/reports/my_report'

    ## processing file: report.Rmd

    ## output file: report.knit.md

David Dorchies's avatar
David Dorchies committed
    ## "C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS report.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output report.tex --lua-filter "C:\Users\ddorchies\AppData\Local\Programs\R\R-4.3.1\library\bookdown\rmarkdown\lua\custom-environment.lua" --lua-filter "C:\Users\ddorchies\AppData\Local\Programs\R\R-4.3.1\library\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\ddorchies\AppData\Local\Programs\R\R-4.3.1\library\rmarkdown\rmarkdown\lua\latex-div.lua" --metadata-file "C:\Users\DDORCH~1\AppData\Local\Temp\RtmpsJQiJu\file5664239a1d39" --embed-resources --standalone --table-of-contents --toc-depth 2 --number-sections --highlight-style tango --pdf-engine pdflatex --biblatex --include-in-header in_header.tex --include-before-body before_body.tex --include-after-body after_body.tex --variable graphics --wrap preserve --variable tables=yes --standalone -Mhas-frontmatter=false
David Dorchies's avatar
David Dorchies committed
    ## Output created: C:/Users/DDORCH~1/AppData/Local/Temp/RtmpsJQiJu/my_fairify_project/public/reports/my_report/report.pdf

## Use data located on the cloud (or not…)
David Dorchies's avatar
David Dorchies committed

Dorch's avatar
Dorch committed
### How it works?
David Dorchies's avatar
David Dorchies committed

The *fairify* project provides a function `getDataPath` which helps you
to use data located on the cloud in your R scripts.
David Dorchies's avatar
David Dorchies committed

Dorch's avatar
Dorch committed
List of supported cloud servers:
David Dorchies's avatar
David Dorchies committed

Dorch's avatar
Dorch committed
- [Owncloud](https://owncloud.com/)
- [Nextcloud](https://nextcloud.com/)
David Dorchies's avatar
David Dorchies committed

Dorch's avatar
Dorch committed
To use it, you first need to define your cloud configuration in the file
`inst/config.yml`:
David Dorchies's avatar
David Dorchies committed

    default:
      data:
        mode: remote
        local: "path_for_data_on_your_disk"
        remote: "https://public_link_on_your_cloud"
        write_results: false
David Dorchies's avatar
David Dorchies committed

The `local` path stands for storing your data on a local or network disk
directly readable and writable by your Operating System.
Dorch's avatar
Dorch committed

### Caching results

`write_results` logical parameter is an helper for caching data results
of long calculations. The basic strategy is to either calculate and save
a result or read this result depending of the value of this boolean:

    computeSomeThing <- function(cfg = loadConfig()) {
      if (cfg$data$write_results) {
        myBigResult <- 2 + 2
        saveRDS(myBigResult, getDataPath("myBigResult.RDS"))
      } else {
        myBigResult <- readRDS(getDataPath("myBigResult.RDS"))
      }
      return(myBigResult)
    }