walkerke / census-with-r-book

Source for Analyzing US Census Data: Methods, Maps, and Models in R by Kyle Walker, published with CRC Press
https://walker-data.com/census-r
Other
81 stars 27 forks source link

Possible error in code block in section 4.5.2? #11

Closed wbdill closed 2 years ago

wbdill commented 2 years ago

4.5.2 Designing and styling the population pyramid

When I run the last code block in 4.5.2 I get:

Error: Breaks and labels are different lengths Run rlang::last_error() to see where the error occurred. In addition: Warning message: Removed 30 rows containing missing values (position_stack).

FYI, the errors go away when I #comment out the following lines:

labels = ~ number_format(scale = .001, suffix = "k")(abs(.x)),

scale_y_discrete(labels = ~ str_remove_all(.x, "Age\\s|\\syears")) + 
walkerke commented 2 years ago

I just checked on my end and it ran without errors. Would you mind posting the results of your sessionInfo()?

wbdill commented 2 years ago
> sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] systemfonts_1.0.2  RColorBrewer_1.1-2 mapview_2.11.0     sf_1.0-7           forcats_0.5.0      stringr_1.4.0      dplyr_1.0.2       
 [8] purrr_0.3.4        readr_1.4.0        tidyr_1.1.2        tibble_3.0.4       ggplot2_3.3.2      tidyverse_1.3.0    tidycensus_1.2.1  
[15] tigris_1.6        

loaded via a namespace (and not attached):
 [1] leafem_0.1.6            colorspace_2.0-0        ellipsis_0.3.1          class_7.3-18            rsconnect_0.8.24       
 [6] leaflet_2.0.4.1         rgdal_1.5-29            rprojroot_2.0.2         snakecase_0.11.0        satellite_1.0.4        
[11] base64enc_0.1-3         fs_1.5.0                rstudioapi_0.13         proxy_0.4-26            farver_2.0.3           
[16] remotes_2.2.0           fansi_0.4.1             lubridate_1.7.9.2       xml2_1.3.3              codetools_0.2-18       
[21] pkgload_1.1.0           jsonlite_1.7.1          broom_0.7.2             dbplyr_2.0.0            png_0.1-7              
[26] compiler_4.0.5          httr_1.4.2              backports_1.2.0         assertthat_0.2.1        cli_2.2.0              
[31] s2_1.0.7                leaflet.providers_1.9.0 htmltools_0.5.1.1       prettyunits_1.1.1       tools_4.0.5            
[36] gtable_0.3.0            glue_1.4.2              wk_0.5.0                rappdirs_0.3.1          Rcpp_1.0.7             
[41] cellranger_1.1.0        raster_3.5-2            vctrs_0.3.5             crosstalk_1.1.0.1       ps_1.4.0               
[46] testthat_3.0.0          rvest_1.0.2             lifecycle_1.0.1         devtools_2.3.2          terra_1.4-11           
[51] scales_1.1.1            hms_0.5.3               yaml_2.2.1              curl_4.3                memoise_1.1.0          
[56] stringi_1.5.3           maptools_1.1-3          desc_1.2.0              e1071_1.7-9             pkgbuild_1.1.0         
[61] rlang_0.4.12            pkgconfig_2.0.3         lattice_0.20-41         htmlwidgets_1.5.4       labeling_0.4.2         
[66] processx_3.4.5          tidyselect_1.1.0        magrittr_2.0.1          R6_2.5.0                generics_0.1.0         
[71] DBI_1.1.0               pillar_1.4.7            haven_2.3.1             foreign_0.8-81          withr_2.3.0            
[76] units_0.7-2             sp_1.4-5                janitor_2.0.1           modelr_0.1.8            crayon_1.3.4           
[81] uuid_0.1-4              KernSmooth_2.23-18      utf8_1.1.4              usethis_1.6.3           grid_4.0.5             
[86] readxl_1.3.1            callr_3.5.1             reprex_0.3.0            digest_0.6.27           classInt_0.4-3         
[91] webshot_0.5.2           stats4_4.0.5            munsell_0.5.0           viridisLite_0.3.0       sessioninfo_1.1.1    
walkerke commented 2 years ago

It's showing that most of your tidyverse packages are not up to date, so I'd recommend updating them (and updating your version of R when you get the chance, as you are missing out on some nice features in R 4.1 and higher).

I think if you do install.packages(c("ggplot2", "scales")), however, it should do the trick.

wbdill commented 2 years ago

Updating R to 4.2.0 and installing needed packages did the trick. Sorry for the false alarm due to my lack of maintenance. :(

BTW (I know you know this already, but) tidycensus is AMAZING! As a hobbyist data nerd and non-professional R user who is new to the overwhelming world of US Census data, this package is just the best!