From 43b4c43337124ed40971f71ca7defc87e923fbe0 Mon Sep 17 00:00:00 2001 From: Jacqueline Date: Thu, 17 Oct 2024 15:03:09 +0100 Subject: [PATCH 01/10] Added a population dataset Co-authored-by: Tom Jemmett Co-authored-by: Gabriel Hobro Co-authored-by: Sarah Lucas --- R/ons_uk_population_2023.R | 65 ++++++++++++++++++++++++++++++++ data/ons_uk_population_2023.rda | Bin 0 -> 5097 bytes 2 files changed, 65 insertions(+) create mode 100644 R/ons_uk_population_2023.R create mode 100644 data/ons_uk_population_2023.rda diff --git a/R/ons_uk_population_2023.R b/R/ons_uk_population_2023.R new file mode 100644 index 0000000..90f7dac --- /dev/null +++ b/R/ons_uk_population_2023.R @@ -0,0 +1,65 @@ +#' ONS Mid-2023 Population Estimate for UK +#' +#' ONS Population Estimates for Mid-year 2023 +#' National and subnational mid-year population estimates for the UK and its +#' constituent countries by administrative area, age and sex (including +#' components of population change, median age and population density). +#' +#' Data sourced from +#' \href{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland} +#' +#' @docType data +#' +#' @keywords datasets ons population +#' +#' @format Tibble with six columns +#' \describe{ +#' \item{sex}{male or female} +#' \item{Code}{The country/geography code} +#' \href{Name}{country of the UK} +#' \item{Geography}{Country} +#' \item{age}{year of age} +#' \item{count}{the number of people in this group} +#' } +#' +#' @source \href{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland}{ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland} +#' +#' @usage data(ons_uk_population_2023) +#' +#' @examples +#' data(ons_uk_population_2023) +#' +#' library(readxl) +#' library(tidyverse) +#' library(tidyr) + +#' Load the data in +#' population_data_2023_f <- read_excel( +#' "C:/Users/jacqueline.grout/Downloads/mye23tablesuk.xlsx", +#' sheet="MYE2 - Females", +#' skip = 7) + +#' population_data_2023_m <- read_excel( +#' "C:/Users/jacqueline.grout/Downloads/mye23tablesuk.xlsx", +#' sheet="MYE2 - Males", +#' skip = 7) + + +#' pivot longer +#' population_data_2023_f <- population_data_2023_f |> +#' select(!`All ages`) |> +#' pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") + +#' population_data_2023_m <- population_data_2023_m |> +#' select(!`All ages`) |> +#' pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") + +#' population_data_combined <- bind_rows( +#' females = population_data_2023_f, +#' males = population_data_2023_m, +#' .id = "sex" +#' ) +#' +#' +#' +"ons_uk_population_2023" diff --git a/data/ons_uk_population_2023.rda b/data/ons_uk_population_2023.rda new file mode 100644 index 0000000000000000000000000000000000000000..7f8f15b6a2c7c4167459c90c4dc071d26f37a47c GIT binary patch literal 5097 zcmb`GS5y<~wuM8H4M^`q1PnbCDWNJFN@ylhLflm8y>|$xbTI*?gc6kALPwA$Md`hT zCPkzpNRKE*CO|+r(0*eJH9X2T0P0M^pc88rYX*(XCB_Iy+%6A86T_C6eq2s zGewH0vY- zbqDK^?J&|(Mbtx1AoB@S*?AjsNTzZ0^Lz+z-VUPyqrq`@3C;srR{9$NcczIO$oofy zy?LnsAUaAPsTHLarA_!A1wEk(S499Qpa1}b3JMtqI8!B1g#&;PAOIbS&_f78Z0V^4 z;IUCqsy|Q25&;mvKXU$8{ZFBsHjY!=!Tl=Tu_1h)pzQDGCP2FFzlTrcA(t-Po@|={pwLG`0c5!+5C~a{J`(ZA_Rmha&giIcnlH7w5M#zl^5k9!D1n{^ z1=BO5rFCJ)up3L1iMnPwn-x0eml2Be3X2GpNJDUPOmQrmq=6*c1PZ0WBN-Fh=Mcv3 z@ouqpW)y>M1n)K8XfO>N|yY%EAk52Xe)yLb?ZdsrKv^4n`K_34!PMP#j` z;$-Y#1$-vt{cJaxyRk*0pOwQvz!ySf07tE9-dBgNMYhh+(#^sT=#QIK>S}#7(PfxE zVOvTQW{-RAJ|fw=zo-ie=5bWfPdrTn{Zj6HkT%7m># z7CYD3HC?l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ject: [PATCH 02/10] Ran documentation --- man/ons_uk_population_2023.Rd | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 man/ons_uk_population_2023.Rd diff --git a/man/ons_uk_population_2023.Rd b/man/ons_uk_population_2023.Rd new file mode 100644 index 0000000..cd27bab --- /dev/null +++ b/man/ons_uk_population_2023.Rd @@ -0,0 +1,67 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ons_uk_population_2023.R +\docType{data} +\name{ons_uk_population_2023} +\alias{ons_uk_population_2023} +\title{ONS Mid-2023 Population Estimate for UK} +\format{ +Tibble with six columns +\describe{ +\item{sex}{male or female} +\item{Code}{The country/geography code} +\href{Name}{country of the UK} +\item{Geography}{Country} +\item{age}{year of age} +\item{count}{the number of people in this group} +} +} +\source{ +\href{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland}{ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland} +} +\usage{ +data(ons_uk_population_2023) +} +\description{ +ONS Population Estimates for Mid-year 2023 +National and subnational mid-year population estimates for the UK and its + constituent countries by administrative area, age and sex (including + components of population change, median age and population density). +} +\details{ +Data sourced from +\href{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland} +} +\examples{ +data(ons_uk_population_2023) + +library(readxl) +library(tidyverse) +library(tidyr) +Load the data in +population_data_2023_f <- read_excel( +"C:/Users/jacqueline.grout/Downloads/mye23tablesuk.xlsx", + sheet="MYE2 - Females", + skip = 7) +population_data_2023_m <- read_excel( + "C:/Users/jacqueline.grout/Downloads/mye23tablesuk.xlsx", + sheet="MYE2 - Males", + skip = 7) +pivot longer +population_data_2023_f <- population_data_2023_f |> + select(!`All ages`) |> + pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") +population_data_2023_m <- population_data_2023_m |> + select(!`All ages`) |> + pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") +population_data_combined <- bind_rows( + females = population_data_2023_f, + males = population_data_2023_m, + .id = "sex" +) + + + +} +\keyword{datasets} +\keyword{ons} +\keyword{population} From 44ba266ab67c857962ad227c858508eb5069be9a Mon Sep 17 00:00:00 2001 From: Jacqueline Date: Thu, 17 Oct 2024 15:58:38 +0100 Subject: [PATCH 03/10] Updated filepath --- R/ons_uk_population_2023.R | 4 ++-- man/ons_uk_population_2023.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/ons_uk_population_2023.R b/R/ons_uk_population_2023.R index 90f7dac..8d6af5e 100644 --- a/R/ons_uk_population_2023.R +++ b/R/ons_uk_population_2023.R @@ -35,12 +35,12 @@ #' Load the data in #' population_data_2023_f <- read_excel( -#' "C:/Users/jacqueline.grout/Downloads/mye23tablesuk.xlsx", +#' "mye23tablesuk.xlsx", #' sheet="MYE2 - Females", #' skip = 7) #' population_data_2023_m <- read_excel( -#' "C:/Users/jacqueline.grout/Downloads/mye23tablesuk.xlsx", +#' "mye23tablesuk.xlsx", #' sheet="MYE2 - Males", #' skip = 7) diff --git a/man/ons_uk_population_2023.Rd b/man/ons_uk_population_2023.Rd index cd27bab..b618978 100644 --- a/man/ons_uk_population_2023.Rd +++ b/man/ons_uk_population_2023.Rd @@ -39,11 +39,11 @@ library(tidyverse) library(tidyr) Load the data in population_data_2023_f <- read_excel( -"C:/Users/jacqueline.grout/Downloads/mye23tablesuk.xlsx", +"mye23tablesuk.xlsx", sheet="MYE2 - Females", skip = 7) population_data_2023_m <- read_excel( - "C:/Users/jacqueline.grout/Downloads/mye23tablesuk.xlsx", + "mye23tablesuk.xlsx", sheet="MYE2 - Males", skip = 7) pivot longer From 16d01468cc44b5b449f6a964170885b3d889a2e2 Mon Sep 17 00:00:00 2001 From: Jacqueline Date: Thu, 17 Oct 2024 16:11:03 +0100 Subject: [PATCH 04/10] Fix comments --- R/ons_uk_population_2023.R | 4 ++-- man/ons_uk_population_2023.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/ons_uk_population_2023.R b/R/ons_uk_population_2023.R index 8d6af5e..963902b 100644 --- a/R/ons_uk_population_2023.R +++ b/R/ons_uk_population_2023.R @@ -33,7 +33,7 @@ #' library(tidyverse) #' library(tidyr) -#' Load the data in +#' #Load the data in #' population_data_2023_f <- read_excel( #' "mye23tablesuk.xlsx", #' sheet="MYE2 - Females", @@ -45,7 +45,7 @@ #' skip = 7) -#' pivot longer +#' #pivot longer #' population_data_2023_f <- population_data_2023_f |> #' select(!`All ages`) |> #' pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") diff --git a/man/ons_uk_population_2023.Rd b/man/ons_uk_population_2023.Rd index b618978..d1b5163 100644 --- a/man/ons_uk_population_2023.Rd +++ b/man/ons_uk_population_2023.Rd @@ -37,7 +37,7 @@ data(ons_uk_population_2023) library(readxl) library(tidyverse) library(tidyr) -Load the data in +#Load the data in population_data_2023_f <- read_excel( "mye23tablesuk.xlsx", sheet="MYE2 - Females", @@ -46,7 +46,7 @@ population_data_2023_m <- read_excel( "mye23tablesuk.xlsx", sheet="MYE2 - Males", skip = 7) -pivot longer +#pivot longer population_data_2023_f <- population_data_2023_f |> select(!`All ages`) |> pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") From 74722ee5b9cbcdbb30cc21f4859c455614b89403 Mon Sep 17 00:00:00 2001 From: Jacqueline Date: Thu, 17 Oct 2024 17:02:35 +0100 Subject: [PATCH 05/10] Replace example and update documentation --- R/ons_uk_population_2023.R | 41 ++++++++++------------------------- man/ons_uk_population_2023.Rd | 35 ++++++++++-------------------- 2 files changed, 24 insertions(+), 52 deletions(-) diff --git a/R/ons_uk_population_2023.R b/R/ons_uk_population_2023.R index 963902b..52769e4 100644 --- a/R/ons_uk_population_2023.R +++ b/R/ons_uk_population_2023.R @@ -29,36 +29,19 @@ #' @examples #' data(ons_uk_population_2023) #' -#' library(readxl) -#' library(tidyverse) +#' +#' library(dplyr) #' library(tidyr) - -#' #Load the data in -#' population_data_2023_f <- read_excel( -#' "mye23tablesuk.xlsx", -#' sheet="MYE2 - Females", -#' skip = 7) - -#' population_data_2023_m <- read_excel( -#' "mye23tablesuk.xlsx", -#' sheet="MYE2 - Males", -#' skip = 7) - - -#' #pivot longer -#' population_data_2023_f <- population_data_2023_f |> -#' select(!`All ages`) |> -#' pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") - -#' population_data_2023_m <- population_data_2023_m |> -#' select(!`All ages`) |> -#' pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") - -#' population_data_combined <- bind_rows( -#' females = population_data_2023_f, -#' males = population_data_2023_m, -#' .id = "sex" -#' ) +#' +#' # create a dataset that has total population by age groups for England +#' ons_uk_population_2023 |> +#' filter(Name=="ENGLAND") |> +#' mutate(age_group = case_when(as.numeric(age)<=17 ~ "0-17", +#' as.numeric(age)>=18 & as.numeric(age)<=64 ~ "18-64", +#' as.numeric(age)>=65 ~ "65+", +#' age=="90+" ~ "65+")) |> +#' group_by(age_group) |> +#' summarise(count=sum(count)) #' #' #' diff --git a/man/ons_uk_population_2023.Rd b/man/ons_uk_population_2023.Rd index d1b5163..69f8273 100644 --- a/man/ons_uk_population_2023.Rd +++ b/man/ons_uk_population_2023.Rd @@ -34,30 +34,19 @@ Data sourced from \examples{ data(ons_uk_population_2023) -library(readxl) -library(tidyverse) + +library(dplyr) library(tidyr) -#Load the data in -population_data_2023_f <- read_excel( -"mye23tablesuk.xlsx", - sheet="MYE2 - Females", - skip = 7) -population_data_2023_m <- read_excel( - "mye23tablesuk.xlsx", - sheet="MYE2 - Males", - skip = 7) -#pivot longer -population_data_2023_f <- population_data_2023_f |> - select(!`All ages`) |> - pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") -population_data_2023_m <- population_data_2023_m |> - select(!`All ages`) |> - pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") -population_data_combined <- bind_rows( - females = population_data_2023_f, - males = population_data_2023_m, - .id = "sex" -) + +# create a dataset that has total population by age groups for England +ons_uk_population_2023 |> +filter(Name=="ENGLAND") |> + mutate(age_group = case_when(as.numeric(age)<=17 ~ "0-17", + as.numeric(age)>=18 & as.numeric(age)<=64 ~ "18-64", + as.numeric(age)>=65 ~ "65+", + age=="90+" ~ "65+")) |> + group_by(age_group) |> + summarise(count=sum(count)) From 14792828262c22cd0300fd1ce06816c1927888a0 Mon Sep 17 00:00:00 2001 From: Jacqueline Date: Thu, 17 Oct 2024 17:55:45 +0100 Subject: [PATCH 06/10] Added source of dataset and executed styler --- R/ons_uk_population_2023.R | 18 ++++++++-------- data-raw/ons_uk_population_2023.R | 34 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 data-raw/ons_uk_population_2023.R diff --git a/R/ons_uk_population_2023.R b/R/ons_uk_population_2023.R index 52769e4..7a006c6 100644 --- a/R/ons_uk_population_2023.R +++ b/R/ons_uk_population_2023.R @@ -35,14 +35,14 @@ #' #' # create a dataset that has total population by age groups for England #' ons_uk_population_2023 |> -#' filter(Name=="ENGLAND") |> -#' mutate(age_group = case_when(as.numeric(age)<=17 ~ "0-17", -#' as.numeric(age)>=18 & as.numeric(age)<=64 ~ "18-64", -#' as.numeric(age)>=65 ~ "65+", -#' age=="90+" ~ "65+")) |> -#' group_by(age_group) |> -#' summarise(count=sum(count)) -#' -#' +#' filter(Name == "ENGLAND") |> +#' mutate(age_group = case_when( +#' as.numeric(age) <= 17 ~ "0-17", +#' as.numeric(age) >= 18 & as.numeric(age) <= 64 ~ "18-64", +#' as.numeric(age) >= 65 ~ "65+", +#' age == "90+" ~ "65+" +#' )) |> +#' group_by(age_group) |> +#' summarise(count = sum(count)) #' "ons_uk_population_2023" diff --git a/data-raw/ons_uk_population_2023.R b/data-raw/ons_uk_population_2023.R new file mode 100644 index 0000000..7d00665 --- /dev/null +++ b/data-raw/ons_uk_population_2023.R @@ -0,0 +1,34 @@ +# Source: https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland + +library(readxl) +library(tidyverse) +library(tidyr) + +# Load the data in +population_data_2023_f <- read_excel( + "mye23tablesuk.xlsx", # add full file path here before file name + sheet = "MYE2 - Females", + skip = 7 +) + +population_data_2023_m <- read_excel( + "mye23tablesuk.xlsx", # add full file path here before file name + sheet = "MYE2 - Males", + skip = 7 +) + + +# pivot longer +population_data_2023_f <- population_data_2023_f |> + select(!`All ages`) |> + pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") + +population_data_2023_m <- population_data_2023_m |> + select(!`All ages`) |> + pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") + +population_data_combined <- bind_rows( + females = population_data_2023_f, + males = population_data_2023_m, + .id = "sex" +) From ef766fc0707bef5a23e14a466d18003e637acacc Mon Sep 17 00:00:00 2001 From: Lextuga007 Date: Thu, 17 Oct 2024 18:16:42 +0100 Subject: [PATCH 07/10] Updated documentation --- man/ons_uk_population_2023.Rd | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/man/ons_uk_population_2023.Rd b/man/ons_uk_population_2023.Rd index 69f8273..b83dd59 100644 --- a/man/ons_uk_population_2023.Rd +++ b/man/ons_uk_population_2023.Rd @@ -40,15 +40,15 @@ library(tidyr) # create a dataset that has total population by age groups for England ons_uk_population_2023 |> -filter(Name=="ENGLAND") |> - mutate(age_group = case_when(as.numeric(age)<=17 ~ "0-17", - as.numeric(age)>=18 & as.numeric(age)<=64 ~ "18-64", - as.numeric(age)>=65 ~ "65+", - age=="90+" ~ "65+")) |> - group_by(age_group) |> - summarise(count=sum(count)) - - + filter(Name == "ENGLAND") |> + mutate(age_group = case_when( + as.numeric(age) <= 17 ~ "0-17", + as.numeric(age) >= 18 & as.numeric(age) <= 64 ~ "18-64", + as.numeric(age) >= 65 ~ "65+", + age == "90+" ~ "65+" + )) |> + group_by(age_group) |> + summarise(count = sum(count)) } \keyword{datasets} From a00500a08f7eed8fd86a87ac656c70b8a2b80c4a Mon Sep 17 00:00:00 2001 From: Lextuga007 Date: Thu, 17 Oct 2024 18:50:09 +0100 Subject: [PATCH 08/10] Added code to create rda file --- data-raw/ons-mortality.R | 2 ++ data-raw/ons_uk_population_2023.R | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/data-raw/ons-mortality.R b/data-raw/ons-mortality.R index 65f8c81..d206575 100644 --- a/data-raw/ons-mortality.R +++ b/data-raw/ons-mortality.R @@ -407,3 +407,5 @@ ons_mortality %>% slice(1) unlink("working_files", recursive = TRUE) + +usethis::use_data(ons_mortality, overwrite = TRUE) diff --git a/data-raw/ons_uk_population_2023.R b/data-raw/ons_uk_population_2023.R index 7d00665..55978a8 100644 --- a/data-raw/ons_uk_population_2023.R +++ b/data-raw/ons_uk_population_2023.R @@ -27,8 +27,10 @@ population_data_2023_m <- population_data_2023_m |> select(!`All ages`) |> pivot_longer(`0`:`90+`, names_to = "age", values_to = "count") -population_data_combined <- bind_rows( +ons_uk_population_2023 <- bind_rows( females = population_data_2023_f, males = population_data_2023_m, .id = "sex" ) + +usethis::use_data(ons_uk_population_2023, overwrite = TRUE) From ca7b8196c00785fb2a581d1f7ba5236805b7713e Mon Sep 17 00:00:00 2001 From: Lextuga007 Date: Thu, 17 Oct 2024 18:52:11 +0100 Subject: [PATCH 09/10] Corrected item mistakenly listed as href and replaced href with url --- R/ons_uk_population_2023.R | 9 +++++---- man/ons_uk_population_2023.Rd | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/R/ons_uk_population_2023.R b/R/ons_uk_population_2023.R index 7a006c6..8d0a5de 100644 --- a/R/ons_uk_population_2023.R +++ b/R/ons_uk_population_2023.R @@ -6,7 +6,7 @@ #' components of population change, median age and population density). #' #' Data sourced from -#' \href{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland} +#' \url{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland} #' #' @docType data #' @@ -15,14 +15,15 @@ #' @format Tibble with six columns #' \describe{ #' \item{sex}{male or female} -#' \item{Code}{The country/geography code} -#' \href{Name}{country of the UK} +#' \item{Code}{country/geography code} +#' \item{Name}{country of the UK} #' \item{Geography}{Country} #' \item{age}{year of age} #' \item{count}{the number of people in this group} #' } #' -#' @source \href{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland}{ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland} +#' @source +#' \url{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland}{ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland} #' #' @usage data(ons_uk_population_2023) #' diff --git a/man/ons_uk_population_2023.Rd b/man/ons_uk_population_2023.Rd index b83dd59..926ab39 100644 --- a/man/ons_uk_population_2023.Rd +++ b/man/ons_uk_population_2023.Rd @@ -8,15 +8,15 @@ Tibble with six columns \describe{ \item{sex}{male or female} -\item{Code}{The country/geography code} -\href{Name}{country of the UK} +\item{Code}{country/geography code} +\item{Name}{country of the UK} \item{Geography}{Country} \item{age}{year of age} \item{count}{the number of people in this group} } } \source{ -\href{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland}{ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland} +\url{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland}{ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland} } \usage{ data(ons_uk_population_2023) @@ -29,7 +29,7 @@ National and subnational mid-year population estimates for the UK and its } \details{ Data sourced from -\href{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland} +\url{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland} } \examples{ data(ons_uk_population_2023) From a47a03e07fc118658143df218ed464dc9126e8df Mon Sep 17 00:00:00 2001 From: Lextuga007 Date: Thu, 17 Oct 2024 21:34:09 +0100 Subject: [PATCH 10/10] Moved url reference as double brackets result in a note --- R/ons_uk_population_2023.R | 11 +++++------ man/ons_uk_population_2023.Rd | 9 ++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/R/ons_uk_population_2023.R b/R/ons_uk_population_2023.R index 8d0a5de..93f38e6 100644 --- a/R/ons_uk_population_2023.R +++ b/R/ons_uk_population_2023.R @@ -2,10 +2,12 @@ #' #' ONS Population Estimates for Mid-year 2023 #' National and subnational mid-year population estimates for the UK and its -#' constituent countries by administrative area, age and sex (including -#' components of population change, median age and population density). +#' constituent countries by administrative area, age and sex (including +#' components of population change, median age and population density). #' -#' Data sourced from +#' ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland +#' +#' @source #' \url{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland} #' #' @docType data @@ -22,9 +24,6 @@ #' \item{count}{the number of people in this group} #' } #' -#' @source -#' \url{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland}{ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland} -#' #' @usage data(ons_uk_population_2023) #' #' @examples diff --git a/man/ons_uk_population_2023.Rd b/man/ons_uk_population_2023.Rd index 926ab39..6b2d37d 100644 --- a/man/ons_uk_population_2023.Rd +++ b/man/ons_uk_population_2023.Rd @@ -16,7 +16,7 @@ Tibble with six columns } } \source{ -\url{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland}{ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland} +\url{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland} } \usage{ data(ons_uk_population_2023) @@ -24,12 +24,11 @@ data(ons_uk_population_2023) \description{ ONS Population Estimates for Mid-year 2023 National and subnational mid-year population estimates for the UK and its - constituent countries by administrative area, age and sex (including - components of population change, median age and population density). +constituent countries by administrative area, age and sex (including +components of population change, median age and population density). } \details{ -Data sourced from -\url{https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland} +ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland } \examples{ data(ons_uk_population_2023)