From 10752220f3e748bcd1ece2334f7f719e3bd235bd Mon Sep 17 00:00:00 2001 From: Lextuga007 Date: Wed, 20 Mar 2024 11:32:39 +0000 Subject: [PATCH] Pre-computed vignette https://ropensci.org/blog/2019/12/08/precompute-vignettes/ --- vignettes/NHSRpopulation.Rmd | 170 +++++++++++++++--- vignettes/NHSRpopulation.Rmd.orig | 154 ++++++++++++++++ .../NHSRpopulation_cache/html/__packages | 9 - ...k-2_5b4cf99805be7dcbf99a7cc27400e7d6.RData | Bin 398 -> 0 bytes ...unk-2_5b4cf99805be7dcbf99a7cc27400e7d6.rdb | Bin 199 -> 0 bytes ...unk-2_5b4cf99805be7dcbf99a7cc27400e7d6.rdx | Bin 162 -> 0 bytes vignettes/articles/Getting-Started.Rmd | 14 ++ 7 files changed, 318 insertions(+), 29 deletions(-) create mode 100644 vignettes/NHSRpopulation.Rmd.orig delete mode 100644 vignettes/NHSRpopulation_cache/html/__packages delete mode 100644 vignettes/NHSRpopulation_cache/html/unnamed-chunk-2_5b4cf99805be7dcbf99a7cc27400e7d6.RData delete mode 100644 vignettes/NHSRpopulation_cache/html/unnamed-chunk-2_5b4cf99805be7dcbf99a7cc27400e7d6.rdb delete mode 100644 vignettes/NHSRpopulation_cache/html/unnamed-chunk-2_5b4cf99805be7dcbf99a7cc27400e7d6.rdx create mode 100644 vignettes/articles/Getting-Started.Rmd diff --git a/vignettes/NHSRpopulation.Rmd b/vignettes/NHSRpopulation.Rmd index ae1eb22..1d0c530 100644 --- a/vignettes/NHSRpopulation.Rmd +++ b/vignettes/NHSRpopulation.Rmd @@ -8,23 +8,15 @@ vignette: > %\VignetteEncoding{UTF-8} --- -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - echo = TRUE, - eval = TRUE, - comment = "#>", - fig.path = "man/figures/README-", - out.width = "100%" -) -``` + ### Indices of Multiple Deprivation (IMD) To get the IMD scores (raw scores and ranked deciles) for a dataset run the following code to generate some random example postcodes: -```{r, eval=TRUE} + +```r library(tibble) library(NHSRpopulation) @@ -35,11 +27,18 @@ tibble_postcodes <- postcodes |> dplyr::rename(postcode = value) tibble_postcodes +#> # A tibble: 3 × 1 +#> postcode +#> +#> 1 HD1 2UT +#> 2 HD1 2UU +#> 3 HD1 2UV ``` Then, using the `get_data()` function for a vector: -```{r,} + +```r # Execution halted NHSRpopulation::get_data(postcodes) |> dplyr::select( @@ -48,11 +47,26 @@ NHSRpopulation::get_data(postcodes) |> result_type, lsoa_code ) +#> ℹ The following postcodes are terminated: +#> HD1 2UT +#> and have been replaced with these current postcodes: +#> HD1 2RD +#> ℹ The following postcodes are invalid: +#> HD1 2UV +#> and have been replaced with these nearby postcodes: +#> HD1 2UD +#> # A tibble: 3 × 4 +#> postcode new_postcode result_type lsoa_code +#> +#> 1 HD1 2UT HD1 2RD terminated E01011107 +#> 2 HD1 2UU HD1 2UU valid E01011229 +#> 3 HD1 2UV HD1 2UD autocompleted E01011229 ``` Or with a data frame: -```{r} + +```r NHSRpopulation::get_data(tibble_postcodes) |> dplyr::select( postcode, @@ -60,6 +74,21 @@ NHSRpopulation::get_data(tibble_postcodes) |> result_type, lsoa_code ) +#> ℹ The following postcodes are terminated: +#> HD1 2UT +#> and have been replaced with these current postcodes: +#> HD1 2RD +#> ℹ The following postcodes are invalid: +#> HD1 2UV +#> and have been replaced with these nearby postcodes: +#> HD1 2UD +#> Joining with `by = join_by(postcode)` +#> # A tibble: 3 × 4 +#> postcode new_postcode result_type lsoa_code +#> +#> 1 HD1 2UT HD1 2RD terminated E01011107 +#> 2 HD1 2UU HD1 2UU valid E01011229 +#> 3 HD1 2UV HD1 2UD autocompleted E01011229 ``` Note that this function uses the {NHSRpostcodetools} package to offer the @@ -69,7 +98,8 @@ the original `postcode` column. Switching off this automatic fix can be done with the code and will accept both vectors and data frames: -```{r} + +```r NHSRpopulation::get_data(tibble_postcodes, fix_invalid = FALSE) |> dplyr::select( postcode, @@ -77,12 +107,26 @@ NHSRpopulation::get_data(tibble_postcodes, fix_invalid = FALSE) |> result_type, lsoa_code ) +#> ℹ The following postcodes are invalid: +#> HD1 2UT +#> but have not been successfully replaced with valid codes. +#> The following postcodes are invalid: +#> HD1 2UV +#> but have not been successfully replaced with valid codes. +#> Joining with `by = join_by(postcode)` +#> # A tibble: 3 × 4 +#> postcode new_postcode result_type lsoa_code +#> +#> 1 HD1 2UT +#> 2 HD1 2UU HD1 2UU valid E01011229 +#> 3 HD1 2UV ``` # Index of Multiple Deprivation -```{r, eval=TRUE} + +```r # Note that the third LSOA in this list is incorrect on purpose imd <- c("E01011107", "E01011229", "E01002") @@ -91,11 +135,18 @@ tibble_imd <- imd |> dplyr::rename(lsoa11 = value) tibble_imd +#> # A tibble: 3 × 1 +#> lsoa11 +#> +#> 1 E01011107 +#> 2 E01011229 +#> 3 E01002 ``` Using the same function but with a parameter/argument to return IMD data: -```{r} + +```r NHSRpopulation::get_data(tibble_imd, url_type = "imd") |> dplyr::select( lsoa11, @@ -103,6 +154,12 @@ NHSRpopulation::get_data(tibble_imd, url_type = "imd") |> imd_decile, imd_score ) +#> # A tibble: 3 × 4 +#> lsoa11 imd_rank imd_decile imd_score +#> +#> 1 E01011107 2928 1 45.6 +#> 2 E01011229 9558 3 27.0 +#> 3 E01002 NA NA NA ``` Data can be either vectors or data frames. @@ -116,39 +173,112 @@ Where data frames are used the expectation of the functions is that postcodes will be in a column called `postcode` and IMD will be from `lsoa11`, however, this can be overwritten: -```{r} + +```r # Create datasets pcs_tb <- dplyr::tibble( pcs = postcodes ) pcs_tb +#> # A tibble: 3 × 1 +#> pcs +#> +#> 1 HD1 2UT +#> 2 HD1 2UU +#> 3 HD1 2UV lsoa_tb <- dplyr::tibble( lower_soa = imd ) lsoa_tb +#> # A tibble: 3 × 1 +#> lower_soa +#> +#> 1 E01011107 +#> 2 E01011229 +#> 3 E01002 ``` The argument/parameter `column = ` can be used to set the column name: -```{r} + +```r NHSRpopulation::get_data(pcs_tb, column = "pcs" ) +#> ℹ The following postcodes are terminated: +#> HD1 2UT +#> and have been replaced with these current postcodes: +#> HD1 2RD +#> ℹ The following postcodes are invalid: +#> HD1 2UV +#> and have been replaced with these nearby postcodes: +#> HD1 2UD +#> Joining with `by = join_by(pcs)` +#> # A tibble: 3 × 40 +#> pcs new_postcode result_type quality eastings northings country nhs_ha longitude latitude european_electoral_r…¹ +#> +#> 1 HD1 2UT HD1 2RD terminated 1 414639 416430 England Yorkshire and the … -1.78 53.6 Yorkshire and The Hum… +#> 2 HD1 2UU HD1 2UU valid 1 414433 416422 England Yorkshire and the … -1.78 53.6 Yorkshire and The Hum… +#> 3 HD1 2UV HD1 2UD autocompleted 1 414371 416317 England Yorkshire and the … -1.78 53.6 Yorkshire and The Hum… +#> # ℹ abbreviated name: ¹​european_electoral_region +#> # ℹ 29 more variables: primary_care_trust , region , lsoa , msoa , incode , outcode , +#> # parliamentary_constituency , parliamentary_constituency_2024 , admin_district , parish , +#> # date_of_introduction , admin_ward , ccg , nuts , pfa , admin_district_code , +#> # admin_county_code , admin_ward_code , parish_code , parliamentary_constituency_code , +#> # parliamentary_constituency_2024_code , ccg_code , ccg_id_code , ced_code , nuts_code , lsoa_code , +#> # msoa_code , lau2_code , pfa_code ``` -```{r} + +```r NHSRpopulation::get_data(lsoa_tb, column = "lower_soa" ) +#> # A tibble: 3 × 66 +#> lower_soa fid lsoa11nm lsoa11nmw st_areasha st_lengths imd_rank imd_decile lsoa01nm la_dcd la_dnm imd_score imd_rank0 imd_dec0 +#> +#> 1 E01011107 11200 Kirklees 0… Kirklees… 1921709. 7525. 2928 1 Kirklee… E0800… Kirkl… 45.6 2928 1 +#> 2 E01011229 11707 Kirklees 0… Kirklees… 833130. 7023. 9558 3 Kirklee… E0800… Kirkl… 27.0 9558 3 +#> 3 E01002 NA NA NA NA NA NA NA NA +#> # ℹ 52 more variables: inc_score , inc_rank , inc_dec , emp_score , emp_rank , emp_dec , +#> # edu_score , edu_rank , edu_dec , hdd_score , hdd_rank , hdd_dec , cri_score , cri_rank , +#> # cri_dec , bhs_score , bhs_rank , bhs_dec , env_score , env_rank , env_dec , idc_score , +#> # idc_rank , idc_dec , ido_score , ido_rank , ido_dec , cyp_score , cyp_rank , cyp_dec , +#> # as_score , as_rank , as_dec , gb_score , gb_rank , gb_dec , wb_score , wb_rank , +#> # wb_dec , ind_score , ind_rank , ind_dec , out_score , out_rank , out_dec , tot_pop , +#> # dep_chi , pop16_59 , pop60 , work_pop , shape_area , shape_length ``` -```{r} + +```r NHSRpopulation::get_data(pcs_tb, # url_type is set to postcodes as default column = "pcs" ) +#> ℹ The following postcodes are terminated: +#> HD1 2UT +#> and have been replaced with these current postcodes: +#> HD1 2RD +#> ℹ The following postcodes are invalid: +#> HD1 2UV +#> and have been replaced with these nearby postcodes: +#> HD1 2UD +#> Joining with `by = join_by(pcs)` +#> # A tibble: 3 × 40 +#> pcs new_postcode result_type quality eastings northings country nhs_ha longitude latitude european_electoral_r…¹ +#> +#> 1 HD1 2UT HD1 2RD terminated 1 414639 416430 England Yorkshire and the … -1.78 53.6 Yorkshire and The Hum… +#> 2 HD1 2UU HD1 2UU valid 1 414433 416422 England Yorkshire and the … -1.78 53.6 Yorkshire and The Hum… +#> 3 HD1 2UV HD1 2UD autocompleted 1 414371 416317 England Yorkshire and the … -1.78 53.6 Yorkshire and The Hum… +#> # ℹ abbreviated name: ¹​european_electoral_region +#> # ℹ 29 more variables: primary_care_trust , region , lsoa , msoa , incode , outcode , +#> # parliamentary_constituency , parliamentary_constituency_2024 , admin_district , parish , +#> # date_of_introduction , admin_ward , ccg , nuts , pfa , admin_district_code , +#> # admin_county_code , admin_ward_code , parish_code , parliamentary_constituency_code , +#> # parliamentary_constituency_2024_code , ccg_code , ccg_id_code , ced_code , nuts_code , lsoa_code , +#> # msoa_code , lau2_code , pfa_code ``` diff --git a/vignettes/NHSRpopulation.Rmd.orig b/vignettes/NHSRpopulation.Rmd.orig new file mode 100644 index 0000000..ae1eb22 --- /dev/null +++ b/vignettes/NHSRpopulation.Rmd.orig @@ -0,0 +1,154 @@ +--- +title: "Getting started with NHSRpopulation" +output: rmarkdown::html_vignette +link-citations: TRUE +vignette: > + %\VignetteIndexEntry{Getting started with NHSRpopulation} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + echo = TRUE, + eval = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +### Indices of Multiple Deprivation (IMD) + +To get the IMD scores (raw scores and ranked deciles) for a dataset run the +following code to generate some random example postcodes: + +```{r, eval=TRUE} +library(tibble) +library(NHSRpopulation) + +postcodes <- c("HD1 2UT", "HD1 2UU", "HD1 2UV") + +tibble_postcodes <- postcodes |> + tibble::as_tibble() |> + dplyr::rename(postcode = value) + +tibble_postcodes +``` + +Then, using the `get_data()` function for a vector: + +```{r,} +# Execution halted +NHSRpopulation::get_data(postcodes) |> + dplyr::select( + postcode, + new_postcode, + result_type, + lsoa_code + ) +``` + +Or with a data frame: + +```{r} +NHSRpopulation::get_data(tibble_postcodes) |> + dplyr::select( + postcode, + new_postcode, + result_type, + lsoa_code + ) +``` + +Note that this function uses the {NHSRpostcodetools} package to offer the +opportunity to fix postcodes which are terminated or are incorrect. +This is default and appears in the column `new_postcode` and does not overwrite +the original `postcode` column. +Switching off this automatic fix can be done with the code and will accept both +vectors and data frames: + +```{r} +NHSRpopulation::get_data(tibble_postcodes, fix_invalid = FALSE) |> + dplyr::select( + postcode, + new_postcode, + result_type, + lsoa_code + ) +``` + +# Index of Multiple Deprivation + + +```{r, eval=TRUE} +# Note that the third LSOA in this list is incorrect on purpose +imd <- c("E01011107", "E01011229", "E01002") + +tibble_imd <- imd |> + tibble::as_tibble() |> + dplyr::rename(lsoa11 = value) + +tibble_imd +``` + +Using the same function but with a parameter/argument to return IMD data: + +```{r} +NHSRpopulation::get_data(tibble_imd, url_type = "imd") |> + dplyr::select( + lsoa11, + imd_rank, + imd_decile, + imd_score + ) +``` + +Data can be either vectors or data frames. + +No corrections are made to incorrect LSOA codes and the current join to the API +is on `lsoa11` data. + +# Column names + +Where data frames are used the expectation of the functions is that postcodes +will be in a column called `postcode` and IMD will be from `lsoa11`, however, +this can be overwritten: + +```{r} +# Create datasets +pcs_tb <- dplyr::tibble( + pcs = postcodes +) + +pcs_tb + +lsoa_tb <- dplyr::tibble( + lower_soa = imd +) + +lsoa_tb +``` + +The argument/parameter `column = ` can be used to set the column name: + +```{r} +NHSRpopulation::get_data(pcs_tb, + column = "pcs" +) +``` + +```{r} +NHSRpopulation::get_data(lsoa_tb, + column = "lower_soa" +) +``` + +```{r} +NHSRpopulation::get_data(pcs_tb, + # url_type is set to postcodes as default + column = "pcs" +) +``` + diff --git a/vignettes/NHSRpopulation_cache/html/__packages b/vignettes/NHSRpopulation_cache/html/__packages deleted file mode 100644 index 2ef2ac1..0000000 --- a/vignettes/NHSRpopulation_cache/html/__packages +++ /dev/null @@ -1,9 +0,0 @@ -base -methods -datasets -utils -grDevices -graphics -stats -tibble -NHSRpopulation diff --git a/vignettes/NHSRpopulation_cache/html/unnamed-chunk-2_5b4cf99805be7dcbf99a7cc27400e7d6.RData b/vignettes/NHSRpopulation_cache/html/unnamed-chunk-2_5b4cf99805be7dcbf99a7cc27400e7d6.RData deleted file mode 100644 index 22f77b604e3eaaabfa514a6e6f230ed2de79e362..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 398 zcmV;90df8xiwFP!000002F;S+YQiuS#H?=(%b zwXC)!O$UWtc(F$q>{)ibH`#-XrGHckdw{_S`F_dCmz;3s(^VI*FhZz;s+9_=)TBf; zb8({#5vra_I6+l(CgVux9$%RX4cb-|JowPnR@n*B(*mEsTc+wQEWqGW1;PSmK+?YT* zzTbB;VBxqC$S7xl*4Em3k@J5dd-vNX+iu}^k{ z2qQyPpIqU@R+|P})psI=D^hJ^-xY~kE?&*eFb;!A(7=|yV+CllKAUzxHy8B_D5QCm z%X$mr{Oi}Hb4PfcV1PWuFi5n{WwVuU*rAtj!{99Kh35VgT)_+RV)lo5T3-XM_m0qo suMg;?t8ln9r!jSSI;YfuqKb_4g3OG%1ufHtk`4Cr3z4Uy8sGu|0QOV diff --git a/vignettes/NHSRpopulation_cache/html/unnamed-chunk-2_5b4cf99805be7dcbf99a7cc27400e7d6.rdb b/vignettes/NHSRpopulation_cache/html/unnamed-chunk-2_5b4cf99805be7dcbf99a7cc27400e7d6.rdb deleted file mode 100644 index 0f60640681d25ec95b01084617f68e09cfb07afe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 199 zcmZQzVDPD!)BPYRAt50xAu%m2A&u2YGQ!#UPKj;<4`T-lv-*Uz?*)b-23)+3Pumt1 z9cH+>i`|=nf#DlYZAph5_>={>9YhQYm@>=w#hqCfUl0h%)6g>SX>4reTqCJ;X4ag^ z5ivb!LeZWX`PC$uO9C!jJ#| g|HqebCw8$+V6o)-)a^a#b8y2lqd&|H1#1-o06T0=J^%m! diff --git a/vignettes/NHSRpopulation_cache/html/unnamed-chunk-2_5b4cf99805be7dcbf99a7cc27400e7d6.rdx b/vignettes/NHSRpopulation_cache/html/unnamed-chunk-2_5b4cf99805be7dcbf99a7cc27400e7d6.rdx deleted file mode 100644 index a15e7b975fd9e218c6affc045983641f4b372f7c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 162 zcmV;T0A2qdiwFP!00000233t+3c@fDgs0u~p#h=bIegX=c!CPPNt&)uuuVyd=kUa8 z{z^5l>||#7<|+XY1QDq664j+WA5K8Ik3rg{pIzSJ9e@5ozW@<*0f9O|CN;A2qKQYz ztY_mEZF(OhqgjTod+=@Zfp>01A{L(vLCPRwOPs%)){>{PgYwk1L|VSHH+}(0CdwzPyhe` diff --git a/vignettes/articles/Getting-Started.Rmd b/vignettes/articles/Getting-Started.Rmd new file mode 100644 index 0000000..f5f7f04 --- /dev/null +++ b/vignettes/articles/Getting-Started.Rmd @@ -0,0 +1,14 @@ +--- +title: "Getting Started" +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(NHSRpopulation) +```