Last updated: 2021-03-27

Checks: 6 1

Knit directory: fa_sim_cal/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20201104) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 462213b. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    .tresorit/
    Ignored:    _targets/
    Ignored:    data/VR_20051125.txt.xz
    Ignored:    output/blk_char.fst
    Ignored:    output/ent_blk.fst
    Ignored:    output/ent_cln.fst
    Ignored:    output/ent_raw.fst
    Ignored:    renv/library/
    Ignored:    renv/local/
    Ignored:    renv/staging/

Untracked files:
    Untracked:  analysis/m_01_1_get_raw_entity_data.Rmd
    Untracked:  analysis/m_01_2_parse_dates.Rmd

Unstaged changes:
    Modified:   R/functions.R
    Modified:   _targets.R
    Modified:   analysis/index.Rmd
    Deleted:    analysis/m_01_get_raw_entity_data.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


# NOTE this notebook can be run manually or automatically by {targets}
# So load the packages required by this notebook here
# rather than relying on _targets.R to load them.

# Set up the project environment, because {workflowr} knits each Rmd file 
# in a new R session, and doesn't execute the project .Rprofile

library(targets) # access data from the targets cache

library(tictoc) # capture execution time
library(here) # construct file paths relative to project root
library(fs) # file system operations
library(vroom) # fast reading of delimited text files
library(tibble) # enhanced data frames
library(lubridate) # date parsing

Attaching package: 'lubridate'
The following objects are masked from 'package:base':

    date, intersect, setdiff, union
# start the execution time clock
tictoc::tic("Computation time (excl. render)")

# Get the path to the raw entity data file
# This is a target managed by {targets}
f_entity_raw_tsv <- tar_read(c_raw_entity_data_file)

1 Introduction

The aim of this set of meta notebooks is to work out how to read the raw entity data. and get it sufficiently neatened so that we can construct standardised names and modelling features without needing any further neatening. To be clear, the target (c_raw_entity_data) corresponding to the objective of this set of notebooks is the neatened raw data, before constructing any modelling features.

This notebook documents the process of parsing the dates from character strings. This is necessary because the subsequent analyses need dates rather than strings that look like dates.

The subsequent notebooks in this set will check that all the columns have been read correctly and work out how to fix them, if necessary. The final notebook in this set works out how to save the neatened data (c_raw_entity_data).

2 Read entity data

Read the raw entity data file using the previously defined function, raw_entity_data_get().

# Show the data file name
fs::path_file(f_entity_raw_tsv)
[1] "VR_20051125.txt.xz"
d <- raw_entity_data_get(f_entity_raw_tsv)

Show some values for all the date columns.

d %>% 
  dplyr::select(ends_with("_dt")) %>% 
  dplyr::slice_sample(n = 10) %>% 
  knitr::kable()
snapshot_dt registr_dt cancellation_dt load_dt
2005-11-25 00:00:00 1998-02-10 00:00:00 NA 2014-07-15 22:21:54.150000000
2005-11-25 00:00:00 1995-04-07 00:00:00 NA 2014-07-15 22:21:54.150000000
2005-11-25 00:00:00 2000-03-10 00:00:00 NA 2014-07-15 22:21:54.150000000
2005-11-25 00:00:00 1980-10-01 00:00:00 NA 2014-07-15 22:21:54.150000000
2005-11-25 00:00:00 1970-03-21 00:00:00 NA 2014-07-15 22:21:54.150000000
2005-11-25 00:00:00 1988-10-07 00:00:00 NA 2014-07-15 22:21:54.150000000
2005-11-25 00:00:00 1974-04-08 00:00:00 NA 2014-07-15 22:21:54.150000000
2005-11-25 00:00:00 2003-08-15 00:00:00 NA 2014-07-15 22:21:54.150000000
2005-11-25 00:00:00 1983-01-01 00:00:00 2000-09-06 00:00:00 2014-07-15 22:21:54.150000000
2005-11-25 00:00:00 2001-01-25 00:00:00 NA 2014-07-15 22:21:54.150000000

Write a function to parse the date columns. We only need the date component of each date-time.

# Function to parse the date strings in the raw entity data
raw_entity_data_parse_dates <- function(
  d # data frame - raw entity data
)
  d %>%
  dplyr::mutate( # convert the datetime cols to dates
    snapshot_dt     = lubridate::as_date(snapshot_dt),
    registr_dt      = lubridate::as_date(registr_dt),
    cancellation_dt = lubridate::as_date(cancellation_dt),
    load_dt         = lubridate::as_date(load_dt)
  )

Test to see if all the dates are parsed and that missing strings map to missing dates.

# get just the character date columns
d_char <- d %>% 
    dplyr::select(ends_with("_dt"))

# parse the date columns
d_date <- d_char %>% 
  raw_entity_data_parse_dates()

# check that the missing values are identically located in both frames
all( is.na(d_char) == is.na(d_date) )
[1] TRUE
  • All missing values are identically located in both frames, so:
    • All nonmissing strings were successfully parsed (otherwise they would be present in d_char and missing in d_date)
    • Missing character strings become missing dates

Timing

Computation time (excl. render): 119.342 sec elapsed

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.10

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
 [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] lubridate_1.7.10 tibble_3.1.0     vroom_1.4.0      fs_1.5.0        
[5] tictoc_1.0       here_1.0.1       workflowr_1.6.2  targets_0.2.0   

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.0  xfun_0.22         bslib_0.2.4       purrr_0.3.4      
 [5] vctrs_0.3.6       generics_0.1.0    htmltools_0.5.1.1 yaml_2.2.1       
 [9] utf8_1.2.1        rlang_0.4.10      later_1.1.0.1     pillar_1.5.1     
[13] jquerylib_0.1.3   DBI_1.1.1         glue_1.4.2        withr_2.4.1      
[17] bit64_4.0.5       lifecycle_1.0.0   stringr_1.4.0     codetools_0.2-18 
[21] evaluate_0.14     knitr_1.31        callr_3.5.1       httpuv_1.5.5     
[25] ps_1.6.0          parallel_4.0.3    fansi_0.4.2       highr_0.8        
[29] Rcpp_1.0.6        renv_0.13.1       promises_1.2.0.1  jsonlite_1.7.2   
[33] bit_4.0.4         digest_0.6.27     stringi_1.5.3     dplyr_1.0.5      
[37] bookdown_0.21     processx_3.4.5    rprojroot_2.0.2   cli_2.3.1        
[41] tools_4.0.3       magrittr_2.0.1    sass_0.3.1        crayon_1.4.1     
[45] pkgconfig_2.0.3   ellipsis_0.3.1    data.table_1.14.0 assertthat_0.2.1 
[49] rmarkdown_2.7     R6_2.5.0          igraph_1.2.6      compiler_4.0.3   
[53] git2r_0.28.0