DebuggingGuide.md

shsannualreport - Debugging Guide

The debugging process described here can be time consuming, so it’s worth pointing out to start with that errors are often visible in the raw data, so it makes sense to check the Excel sheets for any obvious errors before going through this process.

Each of the exported functions in shsannualreport calls a number of internal functions, with output written to the console to inform the user of progress. If errors occur it should be possible to see which function it occured in and debug accordingly.

However, some functions work by looping through a number of excel sheets, reading the sheets to memory and processing them by creating strings of R code dynamically. This can be difficult to debug as the data and executed code are only in memory and so not accessible by the user.

One example of this is in the function shs_create_app_data, which calls internal functions including shs_process_dataset, which then calls other internal functions including shs_process_table_type_1.

When an error occurs in shs_process_table_type_1, there is no immediate way for a user to check either the state of the data at that point, or the code that has been executed. To debug, it’s neecessary to manually step through the code that’s been run to that point, and save the data and the generated code off elsewhere to debug.

Steps

The steps to do this are:

The following instructions are for type 1 tables specifically but can be modified for other table types

Any errors can be now be debugged. If any changes are then required in the original function, the debugging script can be used as the basis to update the code, bearing in mind that as the code is being generated as a string and then evaluated it me be necessary to escape some characters, concatenate new lines etc.



DataScienceScotland/shsannualreport documentation built on Dec. 17, 2021, 4:07 p.m.