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
.
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()
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")
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.