Skip to contents

The goal of dfeR is to help standardise R programming across the Department for Education (DfE), and facilitate sharing of business specific functions, making our code easier to read and write.

Credit to lauraselby for the logo featuring Frederick!

Scope

This package is open to all of DfE and anything we think could be useful to other programmers and analysts can be contributed.

Functionality for dfeR is expected to focus around the following:

  1. DfE specific formatting
  2. Working with Microsoft SQL Databases
  3. Templates for analytical projects
  4. Publication R Markdown Templates
  5. API wrappers for use internally

Documentation for what has been included in the package so far is on our pkgdown site.

We are also developing the dfeshiny package, and expect any functions specific to public facing R Shiny dashboards will live there.


Installation

dfeR is not currently available on CRAN. For the time being you can install the development version from GitHub.

If you are using renv in your project (recommended):

renv::install("dfe-analytical-services/dfeR")

Otherwise:

# install.packages("devtools")
devtools::install_github("dfe-analytical-services/dfeR")

Proxy

The need for setting proxy settings in order to be able to work with R and Git within the DfE estate has now ended. If you previously run the proxy script in previous versions of the dfeR package, then contact the Statistics Development Team to assist in cleaning out your system settings.


Contributing

Ideas for dfeR should first be raised as a GitHub issue after which anyone is free to write the code and create a pull request for review.

For more details on contributing to dfeR, see our contributing guidelines.


Code of Conduct

Please note that the dfeR project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.


Examples

Here are some example formatting functions from within the package:

library(dfeR)

# Prettify large numbers
pretty_num(111111111, gbp = TRUE)
#> [1] "£111.11 million"
pretty_num(-11^8, dp = -1)
#> [1] "-210 million"

# Convert bytes to readable size
pretty_filesize(77777777)
#> [1] "77.78 MB"

# Calculate elapsed time and present prettily
start <- Sys.time()
end <- Sys.time() + 789890
pretty_time_taken(start, end)
#> [1] "219 hours 24 minutes 50 seconds"

# Round 5's up instead of bankers round used by round() in base R
round_five_up(2.5)
#> [1] 3
round(2.5) # base R
#> [1] 2

# Custom formatting for academic and financial years
format_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"

For more details on all the functions available in this package, and examples of how to use them, please see our dfeR package reference documentation.