Skip to content

Commit

Permalink
Merge pull request #44 from nhs-r-community/tidy-package
Browse files Browse the repository at this point in the history
Tidy package
  • Loading branch information
Lextuga007 authored Mar 20, 2024
2 parents 2148338 + 7c76e5c commit 59e3f27
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 144 deletions.
17 changes: 9 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Version: 0.0.2
Authors@R: c(
person("Zoë", "Turner", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0003-1033-9158")),
person("Francis", "Barton", email = "[email protected]",
role = c("aut"), comment = c(ORCID = "0000-0002-5650-1176")),
person("Milan", "Wiedemann", role = c("aut"),
comment = c(ORCID = "0000-0003-1991-282X")),
person("Chris", "Beeley", role = c("aut"),
Expand All @@ -18,23 +20,22 @@ LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
cli,
dplyr,
ggplot2,
jsonlite,
httr2,
janitor,
magrittr,
NHSRpostcodetools,
patchwork,
tidyr
purrr,
rlang,
stringr,
tibble
Depends:
R (>= 2.10)
Suggests:
httptest2,
knitr,
purrr,
rmarkdown,
testthat (>= 3.0.0),
tibble
testthat (>= 3.0.0)
Remotes: nhs-r-community/NHSRpostcodetools
VignetteBuilder: knitr
Config/testthat/edition: 3
21 changes: 0 additions & 21 deletions NHSRpopulation.Rproj

This file was deleted.

18 changes: 10 additions & 8 deletions R/get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ get_data <- function(data,
url_type <- match.arg(url_type)
req <- api_url()
column <- rlang::as_string(column)
value <- NULL
lsoa11cd <- NULL
lsoa_code <- NULL

# Check there is corresponding type data somewhere in data frame
# Use this to allow for other column names to be used in later code
Expand Down Expand Up @@ -68,17 +71,15 @@ get_data <- function(data,
## Generate specific text for the url

if (is.atomic(data) && is_postcode_check == 0 &&
is_lsoa_check > 0) {
is_lsoa_check > 0) {
text <- paste0(
"LSOA11CD IN ('",
paste(data,
collapse = "', '"
), "')"
)
} else if (is.data.frame(data) && is_postcode_check == 0 &&
is_lsoa_check > 0) {
# text <- "1=1" # get all rows (no filter) Takes a while to run

is_lsoa_check > 0) {
text <- paste0(
"LSOA11CD IN ('",
paste(data[[column]],
Expand Down Expand Up @@ -112,7 +113,7 @@ get_data <- function(data,
## IMD data

if (is_postcode_check == 0 && is_lsoa_check > 0 &&
is.data.frame(data)) {
is.data.frame(data)) {
data_out <- imd_api(
text = text,
req = req
Expand Down Expand Up @@ -146,9 +147,10 @@ get_data <- function(data,
)

pc_data |>
dplyr::left_join(data_out,
dplyr::join_by(lsoa_code == lsoa11cd))

dplyr::left_join(
data_out,
dplyr::join_by(lsoa_code == lsoa11cd)
)
} else if (exists("pc_data") && url_type == "postcode") {
pc_data
} else {
Expand Down
14 changes: 0 additions & 14 deletions R/zzz.R

This file was deleted.

6 changes: 6 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ navbar:
right:
- search
- reference
- github

authors:
footer:
roles: [aut]
sidebar:
roles: [aut]
79 changes: 0 additions & 79 deletions tests/testthat/test-get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@ postcodes <- c("HD1 2UT", "HD1 2UU", "HD1 2UV")

imd <- c("E01011107", "E01011229", "E01002")

# # Taken from
# # www.gov.uk/government/statistics/english-indices-of-deprivation-2019
#
# postcodes_from_each_decile <- c(
# "E01000002",
# "E01000001",
# "E01000117",
# "E01000119",
# "E01000069",
# "E01000070",
# "E01000066",
# "E01000005",
# "E01000008",
# "E01000048"
# )
#
## Data frames

test_df1 <- dplyr::tibble(
Expand Down Expand Up @@ -138,69 +122,6 @@ test_that("Returns data with different column names - imd", {
n_col_imd
)
})
# })

# httptest2::with_mock_dir("postcode_message", {
# test_that("Returns message there is no postcode data for data frame", {
# testthat::expect_error(
# get_data(missing_df1, "postcode"),
# paste(
# "There isn't any postcode data in this data frame to",
# "connect to the Postcode API."
# )
# )
# })
#
# test_that("Returns message there is no postcode data for vector", {
# testthat::expect_error(
# get_data(missing_vector, "postcode"),
# paste(
# "There isn't any postcode data in this vector to",
# "connect to the Postcode API."
# )
# )
# })

# test_that("Returns message there is no column called postcode - data frame", {
# testthat::expect_error(
# get_data(no_postcode_colm),
# paste0(
# "There isn't a column called `postcode` in this data frame."
# )
# )
# })
# })

# httptest2::with_mock_dir("imd_message", {
# test_that("Returns message there is no imd data for data frame", {
# testthat::expect_error(
# get_data(missing_df1, "imd"),
# paste(
# "There doesn't appear to be any data in this data frame",
# "to connect to the IMD API."
# )
# )
# })

# test_that("Returns message there is no imd data for vector", {
# testthat::expect_error(
# get_data(missing_vector, "imd"),
# paste(
# "There doesn't appear to be any data in this data frame",
# "to connect to the IMD API."
# )
# )
# })
#
# test_that("Returns message there is no column called lsoa11 - data frame", {
# testthat::expect_error(
# get_data(no_postcode_colm, "imd"),
# paste0(
# "There isn't a column called `lsoa11` in this data frame."
# )
# )
# })
# })

httptest2::with_mock_dir("imd", {
test_that("Returns url_type = 'imd'", {
Expand Down
14 changes: 0 additions & 14 deletions vignettes/articles/Getting-Started.Rmd

This file was deleted.

0 comments on commit 59e3f27

Please sign in to comment.