R/getMetaAllLondon.R

#' @title getMetaAllLondon
#' @description Get the meta data for all air quality monitoring sites in London
#' @param borough_sf A simple-features data frame containing London Borough polygons. , Default: NULL
#' @return A data frame containing meta data for all air quality monitoring sites in London
#' @details If borough_sf is not provided local authority name and inner/outer London category will not be returned.
#' London Borough boundary data is availabe from the \href{https://data.london.gov.uk/dataset/statistical-gis-boundary-files-london}{London DataStore}
#' and \href{https://www.ordnancesurvey.co.uk/business-and-government/products/boundaryline.html}{Ordnance Survey}.
#' @examples 
#' \dontrun{
#' if(interactive()){
#' # Without borough_sf
#' 
#' meta_data <- getMetaAllLondon()
#' 
#' # With borough_sf
#' boroughs <- st_read("London_Borough.shp")
#' meta_data <- getMetaAllLondon(borough_sf = boroughs)
#'  }
#' }
#' @rdname getMetaAllLondon
#' @export 
#' @import checkmate
#' @import dplyr
getMetaAllLondon <- function(borough_sf = NULL) {

#################################### Checks ####################################

  if (!(checkmate::test_null(borough_sf))) {
    checkmate::assert_class(borough_sf, "data.frame")
    checkmate::assert_names(
      x = names(borough_sf),
      must.include = c("LocalAuthorityName", "InnerOuterLondon")
    )
  } else {
    warning("InnerOuterLondon variable will
            not be included as borough_sf not supplied")
  }

######################### Fetch both sets of data ##############################

  aqe_sites <- getMetaAQE(borough_sf)

  laqn_sites <- getMetaLAQN(borough_sf)

############################ Sort and drop dups ################################

  all_sites <- dplyr::bind_rows(aqe_sites, laqn_sites) %>%
    dplyr::arrange(dplyr::desc(network)) %>%
    dplyr::distinct(code, species_code, .keep_all = TRUE) %>%
    dplyr::arrange(local_authority_name, code, species_code)

############################### Return dataframe ###############################

  return(all_sites)

}
LiRogers/LondonAirQuality documentation built on May 27, 2019, 2:06 p.m.