Skip to content

Commit

Permalink
add another param to downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
evanodell committed Jan 23, 2018
1 parent bde6387 commit 97635df
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
16 changes: 12 additions & 4 deletions R/data_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#' sex is an option.
#' @param exclude_missing If \code{TRUE}, excludes all missing values.
#' Defaults to \code{FALSE}.
#' @param additional_queries Any other additional queries to pass to the API.
#' See \url{https://www.nomisweb.co.uk/api/v01/help} for instructions on
#' query structure. Defaults to \code{NULL}.
#'
#' @return A tibble containing the selected dataset.
#' @export
Expand All @@ -41,10 +44,12 @@
#'
#' y <- nomis_get_data(id="NM_1_1", time="latest")
#'
#' z <- nomis_get_data(id="NM_1_1", time="latest", geography="TYPE499", measures=c(20100, 20201), sex=5)
#' z <- nomis_get_data(id="NM_1_1", time="latest", geography="TYPE499",
#' measures=c(20100, 20201), sex=5)
#'
#' }
nomis_get_data <- function(id, time=NULL, geography=NULL, measures=NULL, sex=NULL, exclude_missing=FALSE){
nomis_get_data <- function(id, time=NULL, geography=NULL, measures=NULL,
sex=NULL, exclude_missing=FALSE, additional_queries=NULL){

if(missing(id)){
stop("Dataset ID must be specified")
Expand All @@ -70,11 +75,13 @@ nomis_get_data <- function(id, time=NULL, geography=NULL, measures=NULL, sex=NUL
"&ExcludeMissingValues=true",
"")

query <- paste0("/",id,".data.csv?", time_query, geography_query, measures_query, sex_query, exclude_query)
query <- paste0("/",id,".data.csv?", time_query, geography_query,
measures_query, sex_query, additional_queries, exclude_query)

df <- nomis_collect_util(query)

if(df$RECORD_COUNT[1]>25000) {# test for length and retrieve all data if amount available is over the limit of 25000
if(df$RECORD_COUNT[1]>25000) {
# test for length and retrieve all data if amount available is over the limit of 25000

record_count <- df$RECORD_COUNT[1]

Expand All @@ -101,3 +108,4 @@ nomis_get_data <- function(id, time=NULL, geography=NULL, measures=NULL, sex=NUL
df

}

9 changes: 7 additions & 2 deletions man/nomis_get_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/test_data_collect.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ test_that("nomis_get_data return expected format", {

z <- nomis_get_data(id="NM_1_1", time="latest", geography="TYPE499", measures=c(20100, 20201), sex=5)

expect_length(x, 34)
expect_type(x, "list")
expect_true(tibble::is_tibble(x))
expect_length(z, 34)
expect_type(z, "list")
expect_true(tibble::is_tibble(z))

})

0 comments on commit 97635df

Please sign in to comment.