Rmarkdown to generate demographic profiles for each Scottish Council area.
For each council area we create: data, plots, tables, and text. These elements are then knitted into an HTML document by an RMarkdown file. The whole process is controlled by a single script that loops over each council area.
- Save a copy of the most recent files to a local drive (RMarkdown will knit faster in a local drive)
- Update the data file (including data and last/next updates)
- Check you’re using the latest dataset and only the updated datasets have changed
- Check all the 'next update' dates are still in the future
- Update links to source tables
- Run the script that loops over each council area (this normally takes around 20 mins)
- Sense check the HTML document
- Send a sample of HTML documents to the relevant Statistician for checking
- Send all HTML documents to the web team to upload to the website
- Set a reminder for the next update
- After publication upload changes to GitHub
- Delete old local copies of the code
Branches:
- Provide updated data up to 1 week after any relevant publications
- Let central team know when data has been updated
- Check all content in HTML files is correct (including: data, links, text, next update estimates)
- Correct any issues flagged by the QA scripts. This includes minor issues like "and" vs "&" to retain data provenance.
Statistical Promotion and Analysis:
- Run code and share with branches for QA within 1 week of branches updating any datasets
- Make any changes required by branches and provide web team with HTML files
Statistics Dissemination:
- Upload HTML files within 1 week of them being available
Household Estimates and Projections:
- Household estimates
- Household projections
- Dwellings
- Dwellings by type
- Dwellings by council tax band
Vital Events:
- Births by sex
- Standardised birth rates
- Births by age of mother
- Fertility rates
- Deaths by sex
- Standardised death rates
- Deaths by sex by age
- Leading causes of death
- Life expectancy
- Marriages
- Civil partnerships
Population and Migration Statistics:
- Population estimates
- Population projections
- Nature of population change
- Migration
- Net Migration
- Met migration rates
In rough order of importance/urgency:
- Validate data before preparing tables (e.g. is every council area included? Should Scotland be included? Are all combinations of all variables included? Are values sensible e.g. age < 120?)
- Simplify the code. For example:
- Replace deeply nested
ifelse
withcase_when
orswitch
statements - Use functions and apply DRY
- Use existing utilities
- Replace deeply nested
- Reduce the time it takes to run
- This may be because some datasets are very large
- A solution could be to create aggregate versions of a single dataset
- Automate horizontal axis labels so the final label is for the final datapoint (same for the first)
- Improve/shorten variable names
- Improve comments (e.g. why not what)
- Nest/tidy datasets so the environment is more managable
- Fix Y axis on fertility plot
This repository is available under the Open Government Licence v3.0.