- Notifications
You must be signed in to change notification settings - Fork3
R package for common Department for Education analysis tasks
License
dfe-analytical-services/dfeR
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The goal of dfeR is to help standardise R programming across theDepartment for Education (DfE), and facilitate sharing of businessspecific functions, making our code easier to read and write.
Credit tolauraselby for the logofeaturing Frederick!
This package is open to all of DfE and anything we think could be usefulto other programmers and analysts can be contributed.
Functionality for dfeR is expected to focus around the following:
- DfE specific formatting and helper functions
- Working with DfE databases
- Templates for analytical projects
- API wrappers commonly needed in DfE analysis (where they don’t havetheir own separate package)
- Geography lookup files and helper functions
Documentation for what has been included in the package so far is on ourpkgdown site.
We also maintain thedfeshiny package,and expect any functions specific to R Shiny applications will livethere.
For connecting to data in theexplore educationstatistics, weare building theeesyapi package.
There is agiasrpackage, which has been developed for connecting to data in thegetinformation about schoolsservice.
While we have some DfE specific data in the dfeR package taken from theOpen Geography Portal. If you’relooking at getting new data from the portal it is also worth looking attheboundr package, as thisgives more functions for directly extracting data from there.
dfeR is available on CRAN and can be installed usingpak for faster and more reliable package installation.
Then install dfeR from CRAN:
# If you don’t have pak installed yet, install it first using# install.packages("pak")pak::pak("dfeR")
If you are usingrenv in yourproject (recommended):
renv::install("dfe-analytical-services/dfeR")
Otherwise:
# If you don’t have pak installed yet, install it first using# install.packages("pak")pak::pak("dfe-analytical-services/dfeR")
The need for setting proxy settings in order to be able to work with Rand Git within the DfE estate has now ended. If you previously run theproxy script in previous versions of the dfeR package, then contact theStatistics DevelopmentTeam to assist incleaning out your system settings.
Ideas for dfeR should first be raised as aGitHubissue after whichanyone is free to write the code and create a pull request for review.
For more details on contributing to dfeR, see ourcontributingguidelines.
Please note that the dfeR project is released with aContributor CodeofConduct.By contributing to this project, you agree to abide by its terms.
Here are some example functions from within the package:
library(dfeR)#> Note: The dataset `wd_pcon_lad_la_rgn_ctry` is deprecated and will be removed in the next major release. Use `geo_hierarchy` instead.# Prettify large numberspretty_num(111111111,gbp=TRUE)#> [1] "£111 million"pretty_num(-11^8,dp=-1)#> [1] "-210 million"# Convert bytes to readable sizepretty_filesize(77777777)#> [1] "77.78 MB"# Calculate elapsed time and present prettilystart<- Sys.time()end<- Sys.time()+789890pretty_time_taken(start,end)#> [1] "219 hours 24 minutes 50 seconds"# Round 5's up instead of bankers round used by round() in base Rround_five_up(2.5)#> [1] 3round(2.5)# base R#> [1] 2# Custom formatting for academic and financial yearsformat_ay(202425)#> [1] "2024/25"format_fy(202425)#> [1] "2024-25"format_ay_reverse("2024/25")#> [1] "202425"format_fy_reverse("2024-25")#> [1] "202425"# Get hierachical lookup file for common geographiesmy_data<-dfeR::geo_hierarchyhead(my_data)# show first 5 rows in console#> first_available_year_included most_recent_year_included ward_name#> 1 2017 2021 Abbey#> 2 2022 2023 Abbey#> 3 2024 2025 Abbey#> 4 2017 2017 Abbey#> 5 2024 2025 Abbey#> 6 2017 2023 Abbey#> pcon_name lad_name la_name#> 1 Barking Barking and Dagenham Barking and Dagenham#> 2 Barking Barking and Dagenham Barking and Dagenham#> 3 Barking Barking and Dagenham Barking and Dagenham#> 4 Bath Bath and North East Somerset Bath and North East Somerset#> 5 Belfast North Antrim and Newtownabbey Antrim and Newtownabbey#> 6 Belfast North Antrim and Newtownabbey Antrim and Newtownabbey#> english_devolved_area_name region_name country_name ward_code#> 1 Greater London Authority London England E05000026#> 2 Greater London Authority London England E05014053#> 3 Greater London Authority London England E05014053#> 4 West of England South West England E05001935#> 5 Not applicable Northern Ireland Northern Ireland N08000101#> 6 Not applicable Northern Ireland Northern Ireland N08000101#> pcon_code lad_code old_la_code new_la_code english_devolved_area_code#> 1 E14000540 E09000002 301 E09000002 E61000001#> 2 E14000540 E09000002 301 E09000002 E61000001#> 3 E14001073 E09000002 301 E09000002 E61000001#> 4 E14000547 E06000022 800 E06000022 E47000009#> 5 N05000002 N09000001 z N09000001 z#> 6 N06000002 N09000001 z N09000001 z#> region_code country_code#> 1 E12000007 E92000001#> 2 E12000007 E92000001#> 3 E12000007 E92000001#> 4 E12000009 E92000001#> 5 N92000002 N92000002#> 6 N92000002 N92000002# Get all countriesdfeR::countries#> country_code country_name#> 1 E92000001 England#> 2 K02000001 United Kingdom#> 3 K03000001 Great Britain#> 4 K04000001 England and Wales#> 5 N92000002 Northern Ireland#> 6 S92000003 Scotland#> 7 W92000004 Wales#> 8 z England, Wales and Northern Ireland#> 9 z Outside of England and unknown#> 10 z Outside of the United Kingdom and unknown# Get all PCon names and codes for 2024fetch_pcons(2024)|> head()# show first 5 rows only#> # A tibble: 6 × 2#> pcon_code pcon_name#> <chr> <chr>#> 1 E14001073 Barking#> 2 N05000002 Belfast North#> 3 E14001149 Cambridge#> 4 E14001193 Derby North#> 5 E14001194 Derby South#> 6 S14000073 Dumfries and Galloway# Get All LADs in Scotland in 2017fetch_lads(2017,"Scotland")|> head()# show first 5 rows only#> # A tibble: 6 × 2#> lad_code lad_name#> <chr> <chr>#> 1 S12000006 Dumfries and Galloway#> 2 S12000034 Aberdeenshire#> 3 S12000017 Highland#> 4 S12000044 North Lanarkshire#> 5 S12000033 Aberdeen City#> 6 S12000036 City of Edinburgh# Get all LAs in Scotland and Northern Ireland in 2022fetch_las(2022, c("Scotland","Northern Ireland"))|> head()# show first 5 rows only#> # A tibble: 6 × 3#> new_la_code la_name old_la_code#> <chr> <chr> <chr>#> 1 N09000001 Antrim and Newtownabbey z#> 2 S12000006 Dumfries and Galloway z#> 3 N09000010 Newry, Mourne and Down z#> 4 S12000034 Aberdeenshire z#> 5 N09000008 Mid and East Antrim z#> 6 N09000004 Causeway Coast and Glens z# Get all Welsh wards for 2021fetch_wards(2021,"Wales")|> head()# show first 5 rows only#> # A tibble: 6 × 2#> ward_code ward_name#> <chr> <chr>#> 1 W05000720 Aber Valley#> 2 W05000284 Aber-craf#> 3 W05000357 Aberaeron#> 4 W05000655 Aberaman North#> 5 W05001017 Aberaman South#> 6 W05000551 Aberavon# Get all combined mayoral authorities for 2025fetch_mayoral(2025)|> head()# show first 5 rows only#> # A tibble: 6 × 2#> english_devolved_area_code english_devolved_area_name#> <chr> <chr>#> 1 E61000001 Greater London Authority#> 2 E47000009 West of England#> 3 E47000008 Cambridgeshire and Peterborough#> 4 E47000013 East Midlands#> 5 E47000017 Greater Lincolnshire#> 6 E47000007 West Midlands# The following have no specific years available and return all valuesfetch_regions()#> region_code region_name#> 1 E12000001 North East#> 2 E12000002 North West#> 3 E12000003 Yorkshire and The Humber#> 4 E12000004 East Midlands#> 5 E12000005 West Midlands#> 6 E12000006 East of England#> 7 E12000007 London#> 8 E12000008 South East#> 9 E12000009 South West#> 10 E13000001 Inner London#> 11 E13000002 Outer London#> 12 z Outside of England and unknown#> 13 z Outside of the United Kingdom and unknown#> 14 z Outside of England#> 15 z Outside of United Kingdom#> 16 z Unknownfetch_countries()#> country_code country_name#> 1 E92000001 England#> 2 K02000001 United Kingdom#> 3 K03000001 Great Britain#> 4 K04000001 England and Wales#> 5 N92000002 Northern Ireland#> 6 S92000003 Scotland#> 7 W92000004 Wales#> 8 z England, Wales and Northern Ireland#> 9 z Outside of England and unknown#> 10 z Outside of the United Kingdom and unknown
For more details on all the functions available in this package, andexamples of how to use them, please see ourdfeR package referencedocumentation.
About
R package for common Department for Education analysis tasks
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors12
Uh oh!
There was an error while loading.Please reload this page.
