knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(readflexfile)

One of the core functions of readflexfile is to import the FlexFile into the R environment. readflexfile supports importing both one FlexFile or a folder of multiple FlexFiles into R. The functions:

This vignette demonstrates how to import the FlexFile using readflexfile.

Importing one FlexFile

To import one FlexFile, first point read_flexfile to a .zip of JSON tables of a FlexFile.

file <- system.file("extdata", "Sample_FlexFile_A.zip", package = "flexample")

raw_ff <- read_flexfile(file)

Next, use flatten_data to create a flat file. This joins all ID and name tables, stacks forecasts and actuals, and creates on data frame to work with. In this step, the allocations will also be applied to the actuals data.

flexfile <- raw_ff %>%
  flatten_data()

Importing multiple FlexFiles

To import multiple FlexFiles, point read_folder to a folder of FlexFile submissions. read_function = read_flexfile applies the read_flexfile function to each FlexFile in the folder.

folder <- system.file("extdata", package = "flexample")

raw_ffs <- read_folder(folder, 
                       read_function = read_flexfile)

Just like the single case, use flatten_data to create the flat file for each FlexFile in the list. The function will now return a list of flat files.

flexfiles <- raw_ffs %>%
   flatten_data()

To create a single flat file, simple stack all of the rows from the flattened data. This will stack them all, storing the file name in a column named doc_id.

suppressPackageStartupMessages(library(dplyr))

flexfiles_flat <- flexfiles %>% 
  bind_rows(.id = "doc_id")

Importing the Quantity Data Report

readflexfile also provides functionality for the Quantity Data Report (QDR). The workflow for reading in the QDR is the same as for the FlexFile (and uses many of the same functions).

quantity_data <- system.file("extdata", "Sample_Quantity_A.zip", package = "flexample")

qdr <- read_flexfile(quantity_data) %>%
  flatten_data()


Technomics/readflexfile documentation built on June 13, 2025, 6:14 a.m.