1
+ library(tidyverse )
2
+
3
+
4
+ tb_cases <- read_csv(" https://extranet.who.int/tme/generateCSV.asp?ds=notifications" )
5
+
6
+ # Wrangling
7
+ cases_clean <- tb_cases %> %
8
+ select(- (new_sp : c_newinc ),
9
+ - contains(' _fu' ), - contains(' _mu' ), - contains(' _sexunk' ),
10
+ - contains(' gesex' ), - contains(' 15plus' ), - contains(' 014' ),
11
+ - (rdx_data_available : hiv_reg_new2 )) %> %
12
+ pivot_longer(
13
+ cols = new_sp_m04 : newrel_f65 ,
14
+ names_to = " key" ,
15
+ values_to = " cases" ,
16
+ values_drop_na = TRUE
17
+ ) %> %
18
+ mutate(
19
+ key = stringr :: str_replace(key , " newrel" , " new_rel" )
20
+ ) %> %
21
+ separate(key , c(" new" , " var" , " sexage" )) %> %
22
+ select(- new , - iso2 , - iso3 , - iso_numeric ) %> %
23
+ separate(sexage , c(" sex" , " age" ), sep = 1 ) %> %
24
+ mutate(
25
+ age_middle = case_when(
26
+ age == ' 04' ~ 2 ,
27
+ age == ' 514' ~ 9 ,
28
+ age == ' 1524' ~ 19 ,
29
+ age == ' 2534' ~ 29 ,
30
+ age == ' 3544' ~ 39 ,
31
+ age == ' 4554' ~ 49 ,
32
+ age == ' 5564' ~ 59 ,
33
+ age == ' 65' ~ 75 ),
34
+ var = case_when(
35
+ var == ' sp' ~ ' smear positive' ,
36
+ var == ' sn' ~ ' smear negative' ,
37
+ var == ' rel' ~ ' relapse' ,
38
+ var == ' ep' ~ ' extrapulmonary'
39
+ )) %> %
40
+ select(country , g_whoregion , year , sex , age , age_middle , var , cases )
41
+
42
+
43
+
44
+ # Data details
45
+ dpr_document(tb_cases , extension = " .md.R" , export_folder = usethis :: proj_get(),
46
+ object_name = " tb_cases" ,
47
+ title = " Word Health Organization (WHO) Tuberculosis case notifications by country" ,
48
+ description = " See source for description of the data. tb_dictionary describes the column names." ,
49
+ source = " https://www.who.int/tb/country/data/download/en/" ,
50
+ var_details = list (nothing = " nothing" ))
0 commit comments