From 540aa47c603e8222c097abb60f5c164c7c006c60 Mon Sep 17 00:00:00 2001 From: Erika Rasnick <45949235+erikarasnick@users.noreply.github.com> Date: Tue, 27 Apr 2021 14:03:57 -0400 Subject: [PATCH] Don't remove reporter id column, closes #11 (#12) * remove reporter_person_id * read in date as character then use dht to format * update renv files * Release for image version 2.0.1 --- .gitignore | 2 + README.md | 2 +- docs/mandated_reporter_report.html | 32 +- docs/race_report.html | 32 +- entrypoint.R | 5 +- generate_report.Rmd | 404 - index.Rmd | 13 - mandated_reporter_report.Rmd | 4 +- mandated_reporter_report.html | 7245 ----------------- race_report.html | 7245 ----------------- race_report.rmd | 5 +- renv.lock | 229 +- renv/.gitignore | 2 + renv/activate.R | 411 +- .../simulate_jfs_data.R | 0 ...ata_geocoded_mandated_reporter_report.html | 32 +- ...mulated_jfs_data_geocoded_race_report.html | 32 +- 17 files changed, 590 insertions(+), 15105 deletions(-) delete mode 100644 generate_report.Rmd delete mode 100644 index.Rmd delete mode 100644 mandated_reporter_report.html delete mode 100644 race_report.html rename simulate_jfs_data.R => test/simulate_jfs_data.R (100%) diff --git a/.gitignore b/.gitignore index 2f046a8..25120eb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ .DS_Store old_test/ *geocoding_cache/ +test/test_dates.csv +test/R* diff --git a/README.md b/README.md index a365d55..49d856f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ If `sample_addresses_geocoded.csv` is a file in the current working directory with coordinate columns named `lat` and `lon`, then ```sh -docker run --rm -v $PWD:/tmp degauss/jfs_report_from_geocoded_file:2.0 sample_addresses_geocoded.csv +docker run --rm -v $PWD:/tmp degauss/jfs_report_from_geocoded_file:2.0.1 sample_addresses_geocoded.csv ``` will produce `sample_addresses_geocoded_mandated_reporter_report.html` and `sample_addresses_geocoded_race_report.html`. diff --git a/docs/mandated_reporter_report.html b/docs/mandated_reporter_report.html index f1732e2..2fe3758 100644 --- a/docs/mandated_reporter_report.html +++ b/docs/mandated_reporter_report.html @@ -11,7 +11,7 @@ - + Intakes by Mandated Reporter Neighborhood-Level Report @@ -196,7 +196,7 @@

Intakes by Mandated Reporter Neighborhood-Level Report

-

March 08, 2021

+

April 27, 2021

@@ -215,8 +215,8 @@

Overall Summary

Neighborhood Summary

The table below summarizes intakes, screening decision, mandated reporter status, and demographic information by neighborhood. The table can be sorted by clicking on the column name or searched using the search box.

-
- +
+

Neighborhood Maps

The maps below are interactive and can be panned and zoomed. Clicking on a neighborhood will provide a pop-up with more information about that neighborhood.

@@ -224,12 +224,12 @@

Neighborhood Maps

Intakes per 1000 Households

The two maps below show the Intake Rate (number of intakes per 1000 households) by neighborhood and by mandated reporter status.

-
- +
+
-
- +
+
@@ -254,12 +254,12 @@

Intakes per 1000 Households

Fraction of Intakes Screened In

The two maps below show the Fraction of Intakes Screened In (number of intakes that were screened in / number of intakes) by neighborhood and by mandated reporter status.

-
- +
+
-
- +
+
diff --git a/docs/race_report.html b/docs/race_report.html index 3ca1c26..c9cfc7f 100644 --- a/docs/race_report.html +++ b/docs/race_report.html @@ -11,7 +11,7 @@ - + Alleged Child Victims by Race Neighborhood-Level Report @@ -196,7 +196,7 @@

Alleged Child Victims by Race Neighborhood-Level Report

-

March 08, 2021

+

April 27, 2021

@@ -215,8 +215,8 @@

Overall Summary

Neighborhood Summary

The table below summarizes ACVs, screening decision, race, and demographic information by neighborhood. The table can be sorted by clicking on the column name or searched using the search box.

-
- +
+

Neighborhood Maps

The maps below are interactive and can be panned and zoomed. Clicking on a neighborhood will provide a pop-up with more information about that neighborhood.

@@ -224,12 +224,12 @@

Neighborhood Maps

ACVs per 1000 Children

The two maps below show the ACV Rate (number of acvs per 1000 children) by neighborhood and by race.

-
- +
+
-
- +
+
@@ -254,12 +254,12 @@

ACVs per 1000 Children

Fraction of ACVs Screened In

The two maps below show the Fraction of ACVs Screened In (number of ACVs that were screened in / number of ACVs) by neighborhood and by race.

-
- +
+
-
- +
+
diff --git a/entrypoint.R b/entrypoint.R index 2ea09dd..1d5793a 100755 --- a/entrypoint.R +++ b/entrypoint.R @@ -18,12 +18,12 @@ suppressPackageStartupMessages(library(readr)) d <- read_csv(args$file_name, col_types = cols(INTAKE_ID = col_character(), SCREENING_DECISION = col_character(), - DECISION_DATE = col_date(), + DECISION_DATE = col_character(), PERSON_ID = col_character(), RACE = col_character(), ADDRESS_START = col_date(), MANDATED_REPORTER = col_character(), - REPORTER_PERSON_ID = col_character(), + # REPORTER_PERSON_ID = col_character(), address_type = col_character(), address = col_character(), bad_address = col_logical(), @@ -42,6 +42,7 @@ d <- read_csv(args$file_name, fraction_vacant_housing = col_double(), dep_index = col_double() )) +d <- dplyr::mutate(d, DECISION_DATE = dht::check_dates(DECISION_DATE)) rmarkdown::render(input = '/app/race_report.rmd', params = list(d = d), diff --git a/generate_report.Rmd b/generate_report.Rmd deleted file mode 100644 index a4acae1..0000000 --- a/generate_report.Rmd +++ /dev/null @@ -1,404 +0,0 @@ ---- -title: "JFS Neighborhood-Level Report" -date: "`r format(Sys.time(), '%B %d, %Y')`" -output: - html_document: - df_print: kable -params: - d: d ---- - -```{r setup, include=FALSE} -knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE) - -library(tidyverse) -library(sf) -library(knitr) -library(tmap) -tmap_mode('view') -``` - -```{r} -d <- params$d -# d <- read_csv('test/simulated_jfs_data_geocoded.csv.csv', -# col_types = cols(INTAKE_ID = col_character(), -# PERSON_ID = col_character(), -# REPORTER_PERSON_ID = col_character(), -# PROVIDER_ID = col_character(), -# fips_tract_id = col_character())) -``` - -# Overall Summary - -```{r} -date_min <- min(d$DECISION_DATE) -date_max <- max(d$DECISION_DATE) - -# consider 'SCREENED IN AR' same as 'SCREENED IN' -for (i in 1:nrow(d)) { - if (d$SCREENING_DECISION[i] == 'SCREENED IN AR') { - d$SCREENING_DECISION[i] <- 'SCREENED IN' -} -} -``` - -This report describes `r length(unique(d$INTAKE_ID))` unique intakes with descision dates between `r date_min` and `r date_max` and `r length(unique(d$PERSON_ID))` unique alleged child victims. - -```{r} -d_missing_alleg_add <- d %>% - group_by(INTAKE_ID) %>% - filter(address_type == 'ALLEGATION_ADDRESS', - is.na(address)) %>% - select(INTAKE_ID:address_type) - -d_fill_in_address <- d %>% - filter(INTAKE_ID %in% d_missing_alleg_add$INTAKE_ID, - address_type == 'CHILD_ADDRESS') %>% - group_by(INTAKE_ID) %>% - arrange(desc(ADDRESS_START)) %>% - slice(1) %>% - select(INTAKE_ID, address:dep_index) - -d_missing_alleg_add <- left_join(d_missing_alleg_add, d_fill_in_address, by = 'INTAKE_ID') - -d <- d %>% - filter(address_type == 'ALLEGATION_ADDRESS' & !is.na(address) | - address_type == 'CHILD_ADDRESS') %>% - bind_rows(d_missing_alleg_add) %>% - filter(address_type == 'ALLEGATION_ADDRESS') -``` - -`r length(unique(d_missing_alleg_add$INTAKE_ID))` intakes are missing allegation address. The most recently entered child address will be used. - -### Geocoding Summary - -```{r} -intake_geocode_summary <- d %>% - filter(!duplicated(INTAKE_ID)) %>% - group_by(is.na(lat)) %>% - tally() %>% - mutate(pct = round(n/sum(n)*100,1)) - -child_geocode_summary <- d %>% - filter(!duplicated(PERSON_ID)) %>% - group_by(is.na(lat)) %>% - tally() %>% - mutate(pct = round(n/sum(n)*100,1)) - -rbind(intake_geocode_summary, child_geocode_summary) %>% - filter(`is.na(lat)` == FALSE) %>% - mutate(Level = c('Intake', 'ACV'), - `N` = c(length(unique(d$INTAKE_ID)), length(unique(d$PERSON_ID))), - `N (%) Geocoded` = paste0(n, " (", pct, "%)")) %>% - select(Level, `N`, `N (%) Geocoded`) -``` - -### Deprivation Index by Screening Decision Summary - -Intakes - -```{r} -intake_dep_summary <- d %>% - filter(!duplicated(INTAKE_ID), - !is.na(lat)) %>% - group_by(SCREENING_DECISION) %>% - summarize(mean_dep = round(mean(dep_index, na.rm = T),2), - sd_dep = round(sd(dep_index, na.rm = T), 1)) - -d %>% - filter(!duplicated(INTAKE_ID), - !is.na(lat)) %>% - group_by(SCREENING_DECISION) %>% - tally() %>% - mutate(pct = round(n/sum(n)*100,1), - `N (%)` = glue::glue('{n} ({pct}%)')) %>% - left_join(intake_dep_summary, by = 'SCREENING_DECISION') %>% - mutate(mean_sd = glue::glue('{mean_dep} ({sd_dep})')) %>% - select(Decision = SCREENING_DECISION, `N (%)`, `Deprivation Index Mean (sd) ` = mean_sd) -``` - -ACV - -```{r} -child_dep_summary <- d %>% - filter(!duplicated(PERSON_ID), - !is.na(lat)) %>% - group_by(SCREENING_DECISION) %>% - summarize(mean_dep = round(mean(dep_index, na.rm = T),2), - sd_dep = round(sd(dep_index, na.rm = T), 1)) - -d %>% - filter(!duplicated(PERSON_ID), - !is.na(lat)) %>% - group_by(SCREENING_DECISION) %>% - tally() %>% - mutate(pct = round(n/sum(n)*100,1), - `N (%)` = glue::glue('{n} ({pct}%)')) %>% - left_join(child_dep_summary, by = 'SCREENING_DECISION') %>% - mutate(mean_sd = glue::glue('{mean_dep} ({sd_dep})')) %>% - select(Decision = SCREENING_DECISION, `N (%)`, `Deprivation Index Mean (sd) ` = mean_sd) -``` - -### Mandated Reporter Summary - -```{r} -d_mandated <- d %>% - filter(MANDATED_REPORTER == 'Yes') - -d_mandated_intakes <- unique(d_mandated$INTAKE_ID) - -d <- d %>% - mutate(at_least_one_mandated_reporter = ifelse(INTAKE_ID %in% d_mandated_intakes, 'yes', 'no')) -``` - -`r length(d_mandated_intakes)` (`r round(length(d_mandated_intakes)/length(unique(d$INTAKE_ID))*100,1)`%) intakes were reported by at least one mandated reporter. - -```{r} -d %>% - filter(!duplicated(INTAKE_ID), - !is.na(lat)) %>% - group_by(at_least_one_mandated_reporter, SCREENING_DECISION) %>% - tally() %>% - mutate(pct = round(n/sum(n)*100,1), - `N (%)` = glue::glue('{n} ({pct}%)')) %>% - select(`At Least One Mandated Reporter` = at_least_one_mandated_reporter, - Decision = SCREENING_DECISION, `N (%)`) -``` - - -# Neighborhood Summary - -```{r} -tract_to_neighborhood <- readRDS('/app/tract_to_neighborhood.rds') - -d_neigh_intake <- d %>% - filter(!duplicated(INTAKE_ID)) %>% - mutate(fips_tract_id = as.character(fips_tract_id)) %>% - filter(!is.na(lat)) %>% - left_join(tract_to_neighborhood, by='fips_tract_id') - -intakes_neighborhood <- d_neigh_intake %>% - group_by(neighborhood) %>% - summarize(n_intakes = n()) - -intake_screen_neighborhood <- d_neigh_intake %>% - group_by(neighborhood, SCREENING_DECISION) %>% - tally() %>% - filter(SCREENING_DECISION == 'SCREENED IN') %>% - mutate(n_intakes_screened_in = n) %>% - select(-n, -SCREENING_DECISION) %>% - left_join(intakes_neighborhood, by = 'neighborhood') - -## -mr_intakes_neighborhood <- d_neigh_intake %>% - group_by(neighborhood, at_least_one_mandated_reporter) %>% - summarize(n_mandated_reporter_intakes = n()) %>% - filter(at_least_one_mandated_reporter == 'yes') %>% - ungroup() %>% - select(-at_least_one_mandated_reporter) - -mr_intake_screen_neighborhood <- d_neigh_intake %>% - group_by(neighborhood, at_least_one_mandated_reporter, SCREENING_DECISION) %>% - tally() %>% - filter(at_least_one_mandated_reporter == 'yes', - SCREENING_DECISION == 'SCREENED IN') %>% - mutate(n_mandated_reporter_intakes_screened_in = n) %>% - ungroup() %>% - select(neighborhood, n_mandated_reporter_intakes_screened_in) %>% - left_join(mr_intakes_neighborhood, by = 'neighborhood') - -## - -nmr_intakes_neighborhood <- d_neigh_intake %>% - group_by(neighborhood, at_least_one_mandated_reporter) %>% - summarize(n_nonmandated_reporter_intakes = n()) %>% - filter(at_least_one_mandated_reporter == 'no') %>% - ungroup() %>% - select(-at_least_one_mandated_reporter) - -nmr_intake_screen_neighborhood <- d_neigh_intake %>% - group_by(neighborhood, at_least_one_mandated_reporter, SCREENING_DECISION) %>% - tally() %>% - filter(at_least_one_mandated_reporter == 'no', - SCREENING_DECISION == 'SCREENED IN') %>% - mutate(n_nonmandated_reporter_intakes_screened_in = n) %>% - ungroup() %>% - select(neighborhood, n_nonmandated_reporter_intakes_screened_in) %>% - left_join(nmr_intakes_neighborhood, by = 'neighborhood') - -## -d_neigh_child <- d %>% - filter(!duplicated(PERSON_ID)) %>% - mutate(fips_tract_id = as.character(fips_tract_id)) %>% - filter(!is.na(lat)) %>% - left_join(tract_to_neighborhood, by='fips_tract_id') - -child_neighborhood <- d_neigh_child %>% - group_by(neighborhood) %>% - summarize(n_children = n()) - -child_screen_neighborhood <- d_neigh_child %>% - group_by(neighborhood, SCREENING_DECISION) %>% - tally() %>% - filter(SCREENING_DECISION == 'SCREENED IN') %>% - mutate(n_children_screened_in = n) %>% - select(-n, -SCREENING_DECISION) %>% - left_join(child_neighborhood, by = 'neighborhood') - -d_neighborhood <- intake_screen_neighborhood %>% - left_join(child_screen_neighborhood, by = 'neighborhood') %>% - left_join(mr_intake_screen_neighborhood, by = 'neighborhood') %>% - left_join(nmr_intake_screen_neighborhood, by = 'neighborhood') - -neighborhood_shp <- readRDS('/app/ham_neighborhoods_dep_index_shp.rds') - -d_neighborhood <- neighborhood_shp %>% - left_join(d_neighborhood, by = 'neighborhood') %>% - mutate_at(vars(n_intakes, n_intakes_screened_in, - n_children, n_children_screened_in, - n_mandated_reporter_intakes, n_mandated_reporter_intakes_screened_in), - ~ifelse(.x < 10, NA, .x)) %>% - mutate(n_intakes_per_1000hh = n_intakes/num_hh*1000, - n_intakes_screened_in_per_1000hh = n_intakes_screened_in/num_hh*1000, - intake_fractional_screen_in = n_intakes_screened_in_per_1000hh/n_intakes_per_1000hh, - n_children_per_1000 = n_children/pop_under_18*1000, - n_children_screened_in_per_1000 = n_children_screened_in/pop_under_18*1000, - child_fractional_screen_in = n_children_screened_in_per_1000/n_children_per_1000, - n_intakes_by_mandated_reporter_per_1000hh = n_mandated_reporter_intakes/num_hh*1000, - n_intakes_by_mandated_reporter_screened_in_per_1000hh = n_mandated_reporter_intakes_screened_in/num_hh*1000, - intake_by_mandated_reporter_fractional_screen_in = - n_intakes_by_mandated_reporter_screened_in_per_1000hh/n_intakes_by_mandated_reporter_per_1000hh, - n_intakes_by_nonmandated_reporter_per_1000hh = n_nonmandated_reporter_intakes/num_hh*1000, - n_intakes_by_nonmandated_reporter_screened_in_per_1000hh = n_nonmandated_reporter_intakes_screened_in/num_hh*1000, - intake_by_nonmandated_reporter_fractional_screen_in = - n_intakes_by_nonmandated_reporter_screened_in_per_1000hh/n_intakes_by_nonmandated_reporter_per_1000hh) %>% - mutate_if(is.numeric, ~round(.x, digits = 2)) - -d_neighborhood %>% - st_drop_geometry() %>% - select(Neighborhood = neighborhood, - `Deprivation Index` = dep_index, - `Number of Intakes` = n_intakes, - `Intakes Screened In` = n_intakes_screened_in, - `Number of Households` = num_hh, - `Intake Rate` = n_intakes_per_1000hh, - `Intake Screen-In Rate` = n_intakes_screened_in_per_1000hh, - `Screen-In/Intake` = intake_fractional_screen_in, - `Number of ACV` = n_children, - `Children Screened In` = n_children_screened_in, - `Population under 18` = pop_under_18, - `ACV Rate` = n_children_per_1000, - `ACV Screen-In Rate` = n_children_screened_in_per_1000, - `Screen-In/ACV` = child_fractional_screen_in, - `Number of Intakes by Mandated Reporter` = n_mandated_reporter_intakes, - `Intakes by Mandated Reporter Screened In` = n_mandated_reporter_intakes_screened_in, - `Mandated Reporter Intake Rate` = n_intakes_by_mandated_reporter_per_1000hh, - `Mandated Reporter Intake Screen-In Rate` = n_intakes_by_mandated_reporter_screened_in_per_1000hh, - `Mandated Reporter Screen-In/Intake` = intake_by_mandated_reporter_fractional_screen_in, - `Number of Intakes by Non-Mandated Reporter` = n_nonmandated_reporter_intakes, - `Intakes by Non-Mandated Reporter Screened In` = n_nonmandated_reporter_intakes_screened_in, - `Non-Mandated Reporter Intake Rate` = n_intakes_by_nonmandated_reporter_per_1000hh, - `Non-Mandated Reporter Intake Screen-In Rate` = n_intakes_by_nonmandated_reporter_screened_in_per_1000hh, - `Non-Mandated Reporter Screen-In/Intake` = intake_by_nonmandated_reporter_fractional_screen_in) %>% - DT::datatable() -``` - -## Maps by Intake - -```{r, fig.width = 10, fig.height=8} -tm_basemap("CartoDB.Positron") + - tm_shape(d_neighborhood) + - tm_polygons(col = c('n_intakes_per_1000hh', - 'n_intakes_screened_in_per_1000hh', - 'intake_fractional_screen_in', - 'dep_index'), - title = c('Intake Rate', - 'Intake Screen-In Rate', - 'Screen-In/Intake', - 'Deprivation Index'), - popup.vars = c('Intake Rate' = 'n_intakes_per_1000hh', - 'Intake Screen-In Rate' = 'n_intakes_screened_in_per_1000hh', - 'Screen-In/Intake' = 'intake_fractional_screen_in', - 'Deprivation Index' = 'dep_index'), - alpha = 0.8, - #palette = 'viridis' - ) + - tm_scale_bar() + - tm_layout(frame = FALSE, - asp = 4) -``` - -## Maps by Intake (Mandated Reporter) - -```{r, fig.width = 10, fig.height=8} -tm_basemap("CartoDB.Positron") + - tm_shape(d_neighborhood) + - tm_polygons(col = c('n_intakes_by_mandated_reporter_per_1000hh', - 'n_intakes_by_mandated_reporter_screened_in_per_1000hh', - 'intake_by_mandated_reporter_fractional_screen_in', - 'dep_index'), - title = c('Mandated Reporter Intake Rate', - 'Mandated Reporter Intake Screen-In Rate', - 'Mandated Reporter Screen-In/Intake', - 'Deprivation Index'), - popup.vars = c('Mandated Reporter Intake Rate' = 'n_intakes_by_mandated_reporter_per_1000hh', - 'Mandated Reporter Intake Screen-In Rate' = 'n_intakes_by_mandated_reporter_screened_in_per_1000hh', - 'Mandated Reporter Screen-In/Intake' = 'intake_by_mandated_reporter_fractional_screen_in', - 'Deprivation Index' = 'dep_index'), - alpha = 0.8, - #palette = 'viridis' - ) + - tm_scale_bar() + - tm_layout(frame = FALSE, - asp = 4) -``` - -## Maps by Intake (Non-Mandated Reporter) - -```{r, fig.width = 10, fig.height=8} -tm_basemap("CartoDB.Positron") + - tm_shape(d_neighborhood) + - tm_polygons(col = c('n_intakes_by_nonmandated_reporter_per_1000hh', - 'n_intakes_by_nonmandated_reporter_screened_in_per_1000hh', - 'intake_by_nonmandated_reporter_fractional_screen_in', - 'dep_index'), - title = c('Non-Mandated Reporter Intake Rate', - 'Non-Mandated Reporter Intake Screen-In Rate', - 'Non-Mandated Reporter Screen-In/Intake', - 'Deprivation Index'), - popup.vars = c('Non-Mandated Reporter Intake Rate' = 'n_intakes_by_nonmandated_reporter_per_1000hh', - 'Non-Mandated Reporter Intake Screen-In Rate' = 'n_intakes_by_nonmandated_reporter_screened_in_per_1000hh', - 'Non-Mandated Reporter Screen-In/Intake' = 'intake_by_nonmandated_reporter_fractional_screen_in', - 'Deprivation Index' = 'dep_index'), - alpha = 0.8, - #palette = 'viridis' - ) + - tm_scale_bar() + - tm_layout(frame = FALSE, - asp = 4) -``` - -## Maps by Alleged Child Victim - -```{r, fig.width = 10, fig.height=8} -tm_basemap("CartoDB.Positron") + - tm_shape(d_neighborhood) + - tm_polygons(col = c('n_children_per_1000', - 'n_children_screened_in_per_1000', - 'child_fractional_screen_in', - 'dep_index'), - title = c('ACV Rate', - 'ACV Screen-In Rate', - 'Screen-In/ACV', - 'Deprivation Index'), - popup.vars = c('ACV Rate' = 'n_children_per_1000', - 'ACV Screen-In Rate' = 'n_children_screened_in_per_1000', - 'Screen-In/ACV' = 'child_fractional_screen_in', - 'Deprivation Index' = 'dep_index'), - alpha = 0.8, - # palette = 'viridis' - ) + - tm_scale_bar() + - tm_layout(frame = FALSE, - asp = 4) -``` diff --git a/index.Rmd b/index.Rmd deleted file mode 100644 index 9459e39..0000000 --- a/index.Rmd +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "JFS DeGAUSS Example Reports" -date: "`r format(Sys.time(), '%B %d, %Y')`" -output: html_document ---- - -```{r setup, include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -``` - -[example mandated reporter report](mandated_reporter_report.html) - -[example race report](race_report.html) diff --git a/mandated_reporter_report.Rmd b/mandated_reporter_report.Rmd index b38a2fd..7416834 100644 --- a/mandated_reporter_report.Rmd +++ b/mandated_reporter_report.Rmd @@ -33,7 +33,7 @@ d <- read_csv('test/simulated_jfs_data_geocoded.csv', RACE = col_character(), ADDRESS_START = col_date(), MANDATED_REPORTER = col_character(), - REPORTER_PERSON_ID = col_character(), + # REPORTER_PERSON_ID = col_character(), PROVIDER_ID = col_character(), PROVIDER_NAME = col_character(), address_type = col_character(), @@ -103,7 +103,7 @@ d <- d %>% ```{r} ### Geocoding Summary d_intake <- filter(d, !duplicated(INTAKE_ID)) %>% - select(-PERSON_ID, -RACE, -ADDRESS_START, -REPORTER_PERSON_ID, + select(-PERSON_ID, -RACE, -ADDRESS_START, -address_type) intake_geocode_summary <- d_intake %>% diff --git a/mandated_reporter_report.html b/mandated_reporter_report.html deleted file mode 100644 index 1666f40..0000000 --- a/mandated_reporter_report.html +++ /dev/null @@ -1,7245 +0,0 @@ - - - - - - - - - - - - - - -Intakes by Mandated Reporter Neighborhood-Level Report - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - -
-

Overall Summary

-
    -
  • This report summarizes 5000 intakes with descision dates between 2020-01-01 and 2020-12-31.

  • -
  • 1000 intakes are missing allegation address. The most recently entered child address will be used.

  • -
  • 43 (0.9%) intakes had an address that was not able to be geocoded.

  • -
  • Some intakes have more than one reporter listed. Here, an intake is considered to reported by a mandated reporter if at least one reporter listed is a mandated reporter. 3105 (62.1%) intakes were reported by at least one mandated reporter.

  • -
  • 1827 (59.4%) intakes reported by a mandated reporter were screened in. 1248 (40.6%) intakes reported by a mandated reporter were screened out.

  • -
  • 1122 (59.6%) intakes reported by a non-mandated reporter were screened in. 760 (40.4%) intakes reported by a non-mandated reporter were screened out.

  • -
-
-
-

Neighborhood Summary

-

The table below summarizes intakes, screening decision, mandated reporter status, and demographic information by neighborhood. The table can be sorted by clicking on the column name or searched using the search box.

-
- -
-

Neighborhood Maps

-

The maps below are interactive and can be panned and zoomed. Clicking on a neighborhood will provide a pop-up with more information about that neighborhood.

-
-

Intakes per 1000 Households

-

The two maps below show the Intake Rate (number of intakes per 1000 households) by neighborhood and by mandated reporter status.

-
-
- -
-
-
- -
- -
-
-

Fraction of Intakes Screened In

-

The two maps below show the Fraction of Intakes Screened In (number of intakes that were screened in / number of intakes) by neighborhood and by mandated reporter status.

-
-
- -
-
-
- -
- -
-
-
-

Percent Intakes Screened In Over Time

-

add description/interpretation of charts from Stuart & team

-

-

-
-
- - - - -
- - - - - - - - - - - - - - - diff --git a/race_report.html b/race_report.html deleted file mode 100644 index 4a166b1..0000000 --- a/race_report.html +++ /dev/null @@ -1,7245 +0,0 @@ - - - - - - - - - - - - - - -Alleged Child Victims by Race Neighborhood-Level Report - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - -
-

Overall Summary

-
    -
  • This report summarizes 6976 ACVs with decision dates between 2020-01-01 and 2020-12-31.

  • -
  • 64 (0.9%) ACVs had an address that was not able to be geocoded.

  • -
  • 1516 (46.9%) White ACVs were screened in. 1077 (33.3%) White ACVs were screened out.

  • -
  • 1357 (47%) Black/African American ACVs were screened in. 952 (33%) Black/African American ACVs were screened out.

  • -
  • There were 794 ACVs of neither White nor Black/African American race.

  • -
  • 385 (48.7%) Non-White nor Black/African American ACVs were screened in. 242 (30.6%) Non-White nor Black/African American ACVs were screened out.

  • -
-
-
-

Neighborhood Summary

-

The table below summarizes ACVs, screening decision, race, and demographic information by neighborhood. The table can be sorted by clicking on the column name or searched using the search box.

-
- -
-

Neighborhood Maps

-

The maps below are interactive and can be panned and zoomed. Clicking on a neighborhood will provide a pop-up with more information about that neighborhood.

-
-

ACVs per 1000 Children

-

The two maps below show the ACV Rate (number of acvs per 1000 children) by neighborhood and by race.

-
-
- -
-
-
- -
- -
-
-

Fraction of ACVs Screened In

-

The two maps below show the Fraction of ACVs Screened In (number of ACVs that were screened in / number of ACVs) by neighborhood and by race.

-
-
- -
-
-
- -
- -
-
-
-

Percent ACVs Screened In Over Time

-

add description/interpretation of charts from Stuart & team

-

-

-
-
- - - - -
- - - - - - - - - - - - - - - diff --git a/race_report.rmd b/race_report.rmd index 4e75e4f..a564e0a 100644 --- a/race_report.rmd +++ b/race_report.rmd @@ -33,7 +33,7 @@ d <- read_csv('test/simulated_jfs_data_geocoded.csv', RACE = col_character(), ADDRESS_START = col_date(), MANDATED_REPORTER = col_character(), - REPORTER_PERSON_ID = col_character(), + # REPORTER_PERSON_ID = col_character(), PROVIDER_ID = col_character(), PROVIDER_NAME = col_character(), address_type = col_character(), @@ -102,8 +102,7 @@ d <- d %>% ```{r} ### Geocoding Summary d_acv<- filter(d, !duplicated(PERSON_ID)) %>% - select( -ADDRESS_START, -REPORTER_PERSON_ID, - -address_type) + select( -ADDRESS_START, -address_type) acv_geocode_summary <- d_acv %>% group_by(is.na(lat)) %>% diff --git a/renv.lock b/renv.lock index 5fe76ce..ca12cf8 100644 --- a/renv.lock +++ b/renv.lock @@ -18,10 +18,10 @@ }, "DBI": { "Package": "DBI", - "Version": "1.1.0", + "Version": "1.1.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "4744be45519d675af66c28478720fce5" + "Hash": "030aaec5bc6553f35347cbb1e70b1a17" }, "DT": { "Package": "DT", @@ -53,10 +53,10 @@ }, "R6": { "Package": "R6", - "Version": "2.4.1", + "Version": "2.5.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "292b54f8f4b94669b08f94e5acce6be2" + "Hash": "b203113193e70978a696b2809525649d" }, "RColorBrewer": { "Package": "RColorBrewer", @@ -74,10 +74,10 @@ }, "Rcpp": { "Package": "Rcpp", - "Version": "1.0.3", + "Version": "1.0.6", "Source": "Repository", - "Repository": "RSPM", - "Hash": "f3ca785924863b0e4c8cb23b6a5c75a1" + "Repository": "CRAN", + "Hash": "dbb5e436998a7eba5a9d682060533338" }, "XML": { "Package": "XML", @@ -200,17 +200,17 @@ }, "cli": { "Package": "cli", - "Version": "2.0.1", + "Version": "2.5.0", "Source": "Repository", - "Repository": "RSPM", - "Hash": "5173d8ab28680cf263636b110f4f3220" + "Repository": "CRAN", + "Hash": "a94ba44cee3ea571e813721e64184172" }, "clipr": { "Package": "clipr", - "Version": "0.7.0", + "Version": "0.7.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "08cf4045c149a0f0eaf405324c7495bd" + "Hash": "ebaa97ac99cc2daf04e77eecc7b781d7" }, "colorspace": { "Package": "colorspace", @@ -219,12 +219,26 @@ "Repository": "CRAN", "Hash": "6b436e95723d1f0e861224dd9b094dfb" }, + "cpp11": { + "Package": "cpp11", + "Version": "0.2.7", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "730eebcc741a5c36761f7d4d0f5e37b8" + }, "crayon": { "Package": "crayon", - "Version": "1.3.4", + "Version": "1.4.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "e75525c55c70e5f4f78c9960a4b402e9" + }, + "credentials": { + "Package": "credentials", + "Version": "1.3.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "0d57bc8e27b7ba9e45dba825ebc0de6b" + "Hash": "a96728288c75a814c900af9da84387be" }, "crosstalk": { "Package": "crosstalk", @@ -249,10 +263,22 @@ }, "desc": { "Package": "desc", - "Version": "1.2.0", + "Version": "1.3.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "6c8fe8fa26a23b79949375d372c7b395" + "Hash": "b6963166f7f10b970af1006c462ce6cd" + }, + "dht": { + "Package": "dht", + "Version": "0.0.0.9000", + "Source": "GitHub", + "RemoteType": "github", + "RemoteHost": "api.github.com", + "RemoteRepo": "dht", + "RemoteUsername": "degauss-org", + "RemoteRef": "HEAD", + "RemoteSha": "9fdab695dc26747c44287a7a1604d32f832a260b", + "Hash": "7423434134c7f17a3c92ccad71e07cb9" }, "dichromat": { "Package": "dichromat", @@ -277,17 +303,17 @@ }, "e1071": { "Package": "e1071", - "Version": "1.7-3", + "Version": "1.7-6", "Source": "Repository", "Repository": "CRAN", - "Hash": "728e85416ffc90743054c1ac04486d69" + "Hash": "9a374a10e3c0dbf1a0e207af019bfcea" }, "ellipsis": { "Package": "ellipsis", - "Version": "0.3.0", + "Version": "0.3.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "7067d90c1c780bfe80c0d497e3d7b49d" + "Hash": "fd2844b3a43ae2d27e70ece2df1b4e2a" }, "evaluate": { "Package": "evaluate", @@ -298,10 +324,10 @@ }, "fansi": { "Package": "fansi", - "Version": "0.4.1", + "Version": "0.4.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "7fce217eaaf8016e72065e85c73027b5" + "Hash": "fea074fb67fe4c25d47ad09087da847d" }, "farver": { "Package": "farver", @@ -333,17 +359,24 @@ }, "fs": { "Package": "fs", - "Version": "1.3.1", + "Version": "1.5.0", "Source": "Repository", - "Repository": "RSPM", - "Hash": "0e26be4558dbbc713d7cfe4a4c361f38" + "Repository": "CRAN", + "Hash": "44594a07a42e5f91fac9f93fda6d0109" }, "generics": { "Package": "generics", - "Version": "0.0.2", + "Version": "0.1.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "b8cff1d1391fd1ad8b65877f4c7f2e53" + "Hash": "4d243a9c10b00589889fe32314ffd902" + }, + "gert": { + "Package": "gert", + "Version": "1.3.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "56f398846cd40937be6b435a66bd3f37" }, "ggplot2": { "Package": "ggplot2", @@ -357,6 +390,20 @@ "RemoteSha": "6207d2f8d6ad49a9eda670c874448d6fe454fad1", "Hash": "62b375b8c736652789c1049499d67952" }, + "gh": { + "Package": "gh", + "Version": "1.2.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "346cc58165d33da095c7e67487ec6bca" + }, + "gitcreds": { + "Package": "gitcreds", + "Version": "0.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "f3aefccc1cc50de6338146b62f115de8" + }, "glue": { "Package": "glue", "Version": "1.4.2", @@ -401,10 +448,10 @@ }, "hms": { "Package": "hms", - "Version": "0.5.1", + "Version": "1.0.0", "Source": "Repository", - "Repository": "RSPM", - "Hash": "a89bb57b478154b07be376cb3aff0c3c" + "Repository": "CRAN", + "Hash": "bf552cdd96f5969873afdac7311c7d0d" }, "htmltools": { "Package": "htmltools", @@ -429,10 +476,17 @@ }, "httr": { "Package": "httr", - "Version": "1.4.1", + "Version": "1.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "a525aba14184fec243f9eaec62fbed43" + }, + "ini": { + "Package": "ini", + "Version": "0.3.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "7146fea4685b4252ebf478978c75f597" + "Hash": "6154ec2223172bce8162d4153cda21f7" }, "isoband": { "Package": "isoband", @@ -443,10 +497,10 @@ }, "jsonlite": { "Package": "jsonlite", - "Version": "1.6", + "Version": "1.7.2", "Source": "Repository", - "Repository": "RSPM", - "Hash": "bc5739654d032acf531356e32e0d0f54" + "Repository": "CRAN", + "Hash": "98138e0994d41508c7a6b84a0600cfcb" }, "knitr": { "Package": "knitr", @@ -539,10 +593,10 @@ }, "magrittr": { "Package": "magrittr", - "Version": "1.5", + "Version": "2.0.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "1bb58822a20301cee84a41678e25d9b7" + "Hash": "41287f1ac7d28a92f0a286ed507928d3" }, "maptools": { "Package": "maptools", @@ -574,10 +628,10 @@ }, "mime": { "Package": "mime", - "Version": "0.9", + "Version": "0.10", "Source": "Repository", "Repository": "CRAN", - "Hash": "e87a35ec73b157552814869f45a63aa3" + "Hash": "26fa77e707223e1ce042b2b5d09993dc" }, "modelr": { "Package": "modelr", @@ -602,17 +656,17 @@ }, "openssl": { "Package": "openssl", - "Version": "1.4.1", + "Version": "1.4.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "49f7258fd86ebeaea1df24d9ded00478" + "Hash": "a399e4773075fc2375b71f45fca186c4" }, "pillar": { "Package": "pillar", - "Version": "1.4.3", + "Version": "1.6.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "fa3ed60396b6998d0427c57dab90fba4" + "Hash": "a8c755912ae31910ba6a5d42f5526b6b" }, "pkgbuild": { "Package": "pkgbuild", @@ -698,6 +752,13 @@ "Repository": "CRAN", "Hash": "5cb1623df69ee6102d011c7f78f5791d" }, + "proxy": { + "Package": "proxy", + "Version": "0.4-25", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "29a4dd5b440af584aed8c448d8eefb6e" + }, "ps": { "Package": "ps", "Version": "1.3.0", @@ -707,17 +768,17 @@ }, "purrr": { "Package": "purrr", - "Version": "0.3.3", + "Version": "0.3.4", "Source": "Repository", "Repository": "CRAN", - "Hash": "22aca7d1181718e927d403a8c2d69d62" + "Hash": "97def703420c8ab10d8f0e6c72101e02" }, "rappdirs": { "Package": "rappdirs", - "Version": "0.3.1", + "Version": "0.3.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "8c8298583adbbe76f3c2220eef71bebc" + "Hash": "5e3c5dc0b071b21fa128676560dbe94d" }, "raster": { "Package": "raster", @@ -728,10 +789,10 @@ }, "readr": { "Package": "readr", - "Version": "1.3.1", + "Version": "1.4.0", "Source": "Repository", "Repository": "CRAN", - "Hash": "af8ab99cd936773a148963905736907b" + "Hash": "2639976851f71f330264a9c9c3d43a61" }, "readxl": { "Package": "readxl", @@ -749,10 +810,10 @@ }, "renv": { "Package": "renv", - "Version": "0.10.0", + "Version": "0.13.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "0d3f1c2b63e70b3d918246b4e2ca59b7" + "Hash": "079cb1f03ff972b30401ed05623cbe92" }, "reprex": { "Package": "reprex", @@ -791,17 +852,17 @@ }, "rprojroot": { "Package": "rprojroot", - "Version": "1.3-2", + "Version": "2.0.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "f6a407ae5dd21f6f80a6708bbb6eb3ae" + "Hash": "249d8cd1e74a8f6a26194a91b47f21d1" }, "rstudioapi": { "Package": "rstudioapi", - "Version": "0.10", + "Version": "0.13", "Source": "Repository", - "Repository": "RSPM", - "Hash": "da31c988698b91fdf6a3e2317679d6cb" + "Repository": "CRAN", + "Hash": "06c85365a03fdaf699966cc1d3cf53ea" }, "rvest": { "Package": "rvest", @@ -826,10 +887,10 @@ }, "sf": { "Package": "sf", - "Version": "0.9-7", + "Version": "0.9-8", "Source": "Repository", "Repository": "CRAN", - "Hash": "9d6831c4c002137d99be6b946ac9da07" + "Hash": "d82215b501772c9faadb4dcd71395c7d" }, "shiny": { "Package": "shiny", @@ -868,10 +929,10 @@ }, "stringi": { "Package": "stringi", - "Version": "1.4.6", + "Version": "1.5.3", "Source": "Repository", "Repository": "CRAN", - "Hash": "e99d8d656980d2dd416a962ae55aec90" + "Hash": "a063ebea753c92910a4cca7b18bc1f05" }, "stringr": { "Package": "stringr", @@ -882,10 +943,10 @@ }, "sys": { "Package": "sys", - "Version": "3.3", + "Version": "3.4", "Source": "Repository", "Repository": "CRAN", - "Hash": "507f3116a38d37ad330a038b3be07b66" + "Hash": "b227d13e29222b4574486cfcbde077fa" }, "testthat": { "Package": "testthat", @@ -896,10 +957,10 @@ }, "tibble": { "Package": "tibble", - "Version": "2.1.3", + "Version": "3.1.1", "Source": "Repository", - "Repository": "RSPM", - "Hash": "8248ee35d1e15d1e506f05f5a5d46a75" + "Repository": "CRAN", + "Hash": "fbbca141541ee9242233ba50b0fcb843" }, "tidycensus": { "Package": "tidycensus", @@ -912,7 +973,7 @@ "Package": "tidyr", "Version": "1.0.0", "Source": "URL", - "Repository": "RSPM", + "Repository": "CRAN", "RemoteType": "url", "RemoteUrl": "https://cran.rstudio.com/src/contrib/Archive/tidyr/tidyr_1.0.0.tar.gz", "Hash": "b600c56145ae029818a4af81b1641b0b" @@ -961,17 +1022,24 @@ }, "units": { "Package": "units", - "Version": "0.7-0", + "Version": "0.7-1", "Source": "Repository", "Repository": "CRAN", - "Hash": "57404a7676b139cdcc3e2530508c864e" + "Hash": "1eb71bc3895bf5a047485c16758c4862" + }, + "usethis": { + "Package": "usethis", + "Version": "2.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "360e904f9e623286e1a0c6ca0a98c5f6" }, "utf8": { "Package": "utf8", - "Version": "1.1.4", + "Version": "1.2.1", "Source": "Repository", "Repository": "CRAN", - "Hash": "4a5081acfb7b81a572e4384a7aaf2af1" + "Hash": "c3ad47dc6da0751f18ed53c4613e3ac7" }, "uuid": { "Package": "uuid", @@ -982,10 +1050,10 @@ }, "vctrs": { "Package": "vctrs", - "Version": "0.3.6", + "Version": "0.3.7", "Source": "Repository", "Repository": "CRAN", - "Hash": "5cf1957f93076c19fdc81d01409d240b" + "Hash": "5540dc30a203a43a1ce5dc6a89532b3b" }, "viridis": { "Package": "viridis", @@ -1017,10 +1085,10 @@ }, "withr": { "Package": "withr", - "Version": "2.1.2", + "Version": "2.4.2", "Source": "Repository", "Repository": "CRAN", - "Hash": "aa57ed55ff2df4bea697a07df528993d" + "Hash": "ad03909b44677f930fa156d47d7a3aeb" }, "xfun": { "Package": "xfun", @@ -1045,10 +1113,17 @@ }, "yaml": { "Package": "yaml", - "Version": "2.2.0", + "Version": "2.2.1", "Source": "Repository", - "Repository": "RSPM", - "Hash": "c78bdf1d16bd4ec7ecc86c6986d53309" + "Repository": "CRAN", + "Hash": "2826c5d9efb0a88f657c7a679c7106db" + }, + "zip": { + "Package": "zip", + "Version": "2.1.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "3bc8405c637d988801ec5ea88372d0c2" } } } diff --git a/renv/.gitignore b/renv/.gitignore index 82740ba..993aebf 100644 --- a/renv/.gitignore +++ b/renv/.gitignore @@ -1,3 +1,5 @@ +local/ +lock/ library/ python/ staging/ diff --git a/renv/activate.R b/renv/activate.R index c2fe5e9..b852628 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -2,7 +2,7 @@ local({ # the requested version of renv - version <- "0.10.0" + version <- "0.13.2" # the project directory project <- getwd() @@ -39,12 +39,6 @@ local({ # load bootstrap tools bootstrap <- function(version, library) { - # fix up repos - repos <- getOption("repos") - on.exit(options(repos = repos), add = TRUE) - repos[repos == "@CRAN@"] <- "https://cloud.r-project.org" - options(repos = repos) - # attempt to download renv tarball <- tryCatch(renv_bootstrap_download(version), error = identity) if (inherits(tarball, "error")) @@ -57,34 +51,58 @@ local({ } - renv_bootstrap_download_impl <- function(url, destfile) { + renv_bootstrap_tests_running <- function() { + getOption("renv.tests.running", default = FALSE) + } - mode <- "wb" + renv_bootstrap_repos <- function() { - # https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17715 - fixup <- - Sys.info()[["sysname"]] == "Windows" && - substring(url, 1L, 5L) == "file:" + # check for repos override + repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA) + if (!is.na(repos)) + return(repos) - if (fixup) - mode <- "w+b" + # if we're testing, re-use the test repositories + if (renv_bootstrap_tests_running()) + return(getOption("renv.tests.repos")) - download.file( - url = url, - destfile = destfile, - mode = mode, - quiet = TRUE + # retrieve current repos + repos <- getOption("repos") + + # ensure @CRAN@ entries are resolved + repos[repos == "@CRAN@"] <- getOption( + "renv.repos.cran", + "https://cloud.r-project.org" ) + # add in renv.bootstrap.repos if set + default <- c(FALLBACK = "https://cloud.r-project.org") + extra <- getOption("renv.bootstrap.repos", default = default) + repos <- c(repos, extra) + + # remove duplicates that might've snuck in + dupes <- duplicated(repos) | duplicated(names(repos)) + repos[!dupes] + } renv_bootstrap_download <- function(version) { - methods <- list( - renv_bootstrap_download_cran_latest, - renv_bootstrap_download_cran_archive, - renv_bootstrap_download_github - ) + # if the renv version number has 4 components, assume it must + # be retrieved via github + nv <- numeric_version(version) + components <- unclass(nv)[[1]] + + methods <- if (length(components) == 4L) { + list( + renv_bootstrap_download_github + ) + } else { + list( + renv_bootstrap_download_cran_latest, + renv_bootstrap_download_cran_archive + ) + } for (method in methods) { path <- tryCatch(method(version), error = identity) @@ -96,21 +114,44 @@ local({ } + renv_bootstrap_download_impl <- function(url, destfile) { + + mode <- "wb" + + # https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17715 + fixup <- + Sys.info()[["sysname"]] == "Windows" && + substring(url, 1L, 5L) == "file:" + + if (fixup) + mode <- "w+b" + + utils::download.file( + url = url, + destfile = destfile, + mode = mode, + quiet = TRUE + ) + + } + renv_bootstrap_download_cran_latest <- function(version) { - # check for renv on CRAN matching this version - db <- as.data.frame(available.packages(), stringsAsFactors = FALSE) - if (!"renv" %in% rownames(db)) - stop("renv is not available on your declared package repositories") + spec <- renv_bootstrap_download_cran_latest_find(version) - entry <- db["renv", ] - if (!identical(entry$Version, version)) - stop("renv is not available on your declared package repositories") + message("* Downloading renv ", version, " ... ", appendLF = FALSE) - message("* Downloading renv ", version, " from CRAN ... ", appendLF = FALSE) + type <- spec$type + repos <- spec$repos info <- tryCatch( - download.packages("renv", destdir = tempdir()), + utils::download.packages( + pkgs = "renv", + destdir = tempdir(), + repos = repos, + type = type, + quiet = TRUE + ), condition = identity ) @@ -119,19 +160,65 @@ local({ return(FALSE) } - message("OK") + # report success and return + message("OK (downloaded ", type, ")") info[1, 2] } + renv_bootstrap_download_cran_latest_find <- function(version) { + + # check whether binaries are supported on this system + binary <- + getOption("renv.bootstrap.binary", default = TRUE) && + !identical(.Platform$pkgType, "source") && + !identical(getOption("pkgType"), "source") && + Sys.info()[["sysname"]] %in% c("Darwin", "Windows") + + types <- c(if (binary) "binary", "source") + + # iterate over types + repositories + for (type in types) { + for (repos in renv_bootstrap_repos()) { + + # retrieve package database + db <- tryCatch( + as.data.frame( + utils::available.packages(type = type, repos = repos), + stringsAsFactors = FALSE + ), + error = identity + ) + + if (inherits(db, "error")) + next + + # check for compatible entry + entry <- db[db$Package %in% "renv" & db$Version %in% version, ] + if (nrow(entry) == 0) + next + + # found it; return spec to caller + spec <- list(entry = entry, type = type, repos = repos) + return(spec) + + } + } + + # if we got here, we failed to find renv + fmt <- "renv %s is not available from your declared package repositories" + stop(sprintf(fmt, version)) + + } + renv_bootstrap_download_cran_archive <- function(version) { name <- sprintf("renv_%s.tar.gz", version) - repos <- getOption("repos") + repos <- renv_bootstrap_repos() urls <- file.path(repos, "src/contrib/Archive/renv", name) destfile <- file.path(tempdir(), name) - message("* Downloading renv ", version, " from CRAN archive ... ", appendLF = FALSE) + message("* Downloading renv ", version, " ... ", appendLF = FALSE) for (url in urls) { @@ -190,7 +277,7 @@ local({ return(FALSE) } - message("Done!") + message("OK") return(destfile) } @@ -222,7 +309,7 @@ local({ } - renv_bootstrap_prefix <- function() { + renv_bootstrap_platform_prefix <- function() { # construct version prefix version <- paste(R.version$major, R.version$minor, sep = ".") @@ -241,8 +328,8 @@ local({ components <- c(prefix, R.version$platform) # include prefix if provided by user - prefix <- Sys.getenv("RENV_PATHS_PREFIX") - if (nzchar(prefix)) + prefix <- renv_bootstrap_platform_prefix_impl() + if (!is.na(prefix) && nzchar(prefix)) components <- c(prefix, components) # build prefix @@ -250,6 +337,152 @@ local({ } + renv_bootstrap_platform_prefix_impl <- function() { + + # if an explicit prefix has been supplied, use it + prefix <- Sys.getenv("RENV_PATHS_PREFIX", unset = NA) + if (!is.na(prefix)) + return(prefix) + + # if the user has requested an automatic prefix, generate it + auto <- Sys.getenv("RENV_PATHS_PREFIX_AUTO", unset = NA) + if (auto %in% c("TRUE", "True", "true", "1")) + return(renv_bootstrap_platform_prefix_auto()) + + # empty string on failure + "" + + } + + renv_bootstrap_platform_prefix_auto <- function() { + + prefix <- tryCatch(renv_bootstrap_platform_os(), error = identity) + if (inherits(prefix, "error") || prefix %in% "unknown") { + + msg <- paste( + "failed to infer current operating system", + "please file a bug report at https://github.com/rstudio/renv/issues", + sep = "; " + ) + + warning(msg) + + } + + prefix + + } + + renv_bootstrap_platform_os <- function() { + + sysinfo <- Sys.info() + sysname <- sysinfo[["sysname"]] + + # handle Windows + macOS up front + if (sysname == "Windows") + return("windows") + else if (sysname == "Darwin") + return("macos") + + # check for os-release files + for (file in c("/etc/os-release", "/usr/lib/os-release")) + if (file.exists(file)) + return(renv_bootstrap_platform_os_via_os_release(file, sysinfo)) + + # check for redhat-release files + if (file.exists("/etc/redhat-release")) + return(renv_bootstrap_platform_os_via_redhat_release()) + + "unknown" + + } + + renv_bootstrap_platform_os_via_os_release <- function(file, sysinfo) { + + # read /etc/os-release + release <- utils::read.table( + file = file, + sep = "=", + quote = c("\"", "'"), + col.names = c("Key", "Value"), + comment.char = "#", + stringsAsFactors = FALSE + ) + + vars <- as.list(release$Value) + names(vars) <- release$Key + + # get os name + os <- tolower(sysinfo[["sysname"]]) + + # read id + id <- "unknown" + for (field in c("ID", "ID_LIKE")) { + if (field %in% names(vars) && nzchar(vars[[field]])) { + id <- vars[[field]] + break + } + } + + # read version + version <- "unknown" + for (field in c("UBUNTU_CODENAME", "VERSION_CODENAME", "VERSION_ID", "BUILD_ID")) { + if (field %in% names(vars) && nzchar(vars[[field]])) { + version <- vars[[field]] + break + } + } + + # join together + paste(c(os, id, version), collapse = "-") + + } + + renv_bootstrap_platform_os_via_redhat_release <- function() { + + # read /etc/redhat-release + contents <- readLines("/etc/redhat-release", warn = FALSE) + + # infer id + id <- if (grepl("centos", contents, ignore.case = TRUE)) + "centos" + else if (grepl("redhat", contents, ignore.case = TRUE)) + "redhat" + else + "unknown" + + # try to find a version component (very hacky) + version <- "unknown" + + parts <- strsplit(contents, "[[:space:]]")[[1L]] + for (part in parts) { + + nv <- tryCatch(numeric_version(part), error = identity) + if (inherits(nv, "error")) + next + + version <- nv[1, 1] + break + + } + + paste(c("linux", id, version), collapse = "-") + + } + + renv_bootstrap_library_root_name <- function(project) { + + # use project name as-is if requested + asis <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT_ASIS", unset = "FALSE") + if (asis) + return(basename(project)) + + # otherwise, disambiguate based on project's path + id <- substring(renv_bootstrap_hash_text(project), 1L, 8L) + paste(basename(project), id, sep = "-") + + } + renv_bootstrap_library_root <- function(project) { path <- Sys.getenv("RENV_PATHS_LIBRARY", unset = NA) @@ -257,10 +490,13 @@ local({ return(path) path <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT", unset = NA) - if (!is.na(path)) - return(file.path(path, basename(project))) + if (!is.na(path)) { + name <- renv_bootstrap_library_root_name(project) + return(file.path(path, name)) + } - file.path(project, "renv/library") + prefix <- renv_bootstrap_profile_prefix() + paste(c(project, prefix, "renv/library"), collapse = "/") } @@ -279,8 +515,8 @@ local({ paste("renv", loadedversion, sep = "@") fmt <- paste( - "renv %1$s was loaded from project library, but renv %2$s is recorded in lockfile.", - "Use `renv::record(\"%3$s\")` to record this version in the lockfile.", + "renv %1$s was loaded from project library, but this project is configured to use renv %2$s.", + "Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.", "Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", sep = "\n" ) @@ -292,6 +528,16 @@ local({ } + renv_bootstrap_hash_text <- function(text) { + + hashfile <- tempfile("renv-hash-") + on.exit(unlink(hashfile), add = TRUE) + + writeLines(text, con = hashfile) + tools::md5sum(hashfile) + + } + renv_bootstrap_load <- function(project, libpath, version) { # try to load renv from the project library @@ -307,12 +553,69 @@ local({ TRUE } + + renv_bootstrap_profile_load <- function(project) { + + # if RENV_PROFILE is already set, just use that + profile <- Sys.getenv("RENV_PROFILE", unset = NA) + if (!is.na(profile) && nzchar(profile)) + return(profile) + + # check for a profile file (nothing to do if it doesn't exist) + path <- file.path(project, "renv/local/profile") + if (!file.exists(path)) + return(NULL) + + # read the profile, and set it if it exists + contents <- readLines(path, warn = FALSE) + if (length(contents) == 0L) + return(NULL) + + # set RENV_PROFILE + profile <- contents[[1L]] + if (nzchar(profile)) + Sys.setenv(RENV_PROFILE = profile) + + profile + + } + + renv_bootstrap_profile_prefix <- function() { + profile <- renv_bootstrap_profile_get() + if (!is.null(profile)) + return(file.path("renv/profiles", profile)) + } + + renv_bootstrap_profile_get <- function() { + profile <- Sys.getenv("RENV_PROFILE", unset = "") + renv_bootstrap_profile_normalize(profile) + } + + renv_bootstrap_profile_set <- function(profile) { + profile <- renv_bootstrap_profile_normalize(profile) + if (is.null(profile)) + Sys.unsetenv("RENV_PROFILE") + else + Sys.setenv(RENV_PROFILE = profile) + } + + renv_bootstrap_profile_normalize <- function(profile) { + + if (is.null(profile) || profile %in% c("", "default")) + return(NULL) + + profile + + } + + # load the renv profile, if any + renv_bootstrap_profile_load(project) # construct path to library root root <- renv_bootstrap_library_root(project) # construct library prefix for platform - prefix <- renv_bootstrap_prefix() + prefix <- renv_bootstrap_platform_prefix() # construct full libpath libpath <- file.path(root, prefix) @@ -321,12 +624,22 @@ local({ if (renv_bootstrap_load(project, libpath, version)) return(TRUE) - # load failed; attempt to bootstrap + # load failed; inform user we're about to bootstrap + prefix <- paste("# Bootstrapping renv", version) + postfix <- paste(rep.int("-", 77L - nchar(prefix)), collapse = "") + header <- paste(prefix, postfix) + message(header) + + # perform bootstrap bootstrap(version, libpath) + # exit early if we're just testing bootstrap + if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) + return(TRUE) + # try again to load if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { - message("Successfully installed and loaded renv ", version, ".") + message("* Successfully installed and loaded renv ", version, ".") return(renv::load()) } diff --git a/simulate_jfs_data.R b/test/simulate_jfs_data.R similarity index 100% rename from simulate_jfs_data.R rename to test/simulate_jfs_data.R diff --git a/test/simulated_jfs_data_geocoded_mandated_reporter_report.html b/test/simulated_jfs_data_geocoded_mandated_reporter_report.html index f1732e2..2fe3758 100644 --- a/test/simulated_jfs_data_geocoded_mandated_reporter_report.html +++ b/test/simulated_jfs_data_geocoded_mandated_reporter_report.html @@ -11,7 +11,7 @@ - + Intakes by Mandated Reporter Neighborhood-Level Report @@ -196,7 +196,7 @@

Intakes by Mandated Reporter Neighborhood-Level Report

-

March 08, 2021

+

April 27, 2021

@@ -215,8 +215,8 @@

Overall Summary

Neighborhood Summary

The table below summarizes intakes, screening decision, mandated reporter status, and demographic information by neighborhood. The table can be sorted by clicking on the column name or searched using the search box.

-
- +
+

Neighborhood Maps

The maps below are interactive and can be panned and zoomed. Clicking on a neighborhood will provide a pop-up with more information about that neighborhood.

@@ -224,12 +224,12 @@

Neighborhood Maps

Intakes per 1000 Households

The two maps below show the Intake Rate (number of intakes per 1000 households) by neighborhood and by mandated reporter status.

-
- +
+
-
- +
+
@@ -254,12 +254,12 @@

Intakes per 1000 Households

Fraction of Intakes Screened In

The two maps below show the Fraction of Intakes Screened In (number of intakes that were screened in / number of intakes) by neighborhood and by mandated reporter status.

-
- +
+
-
- +
+
diff --git a/test/simulated_jfs_data_geocoded_race_report.html b/test/simulated_jfs_data_geocoded_race_report.html index 3ca1c26..c9cfc7f 100644 --- a/test/simulated_jfs_data_geocoded_race_report.html +++ b/test/simulated_jfs_data_geocoded_race_report.html @@ -11,7 +11,7 @@ - + Alleged Child Victims by Race Neighborhood-Level Report @@ -196,7 +196,7 @@

Alleged Child Victims by Race Neighborhood-Level Report

-

March 08, 2021

+

April 27, 2021

@@ -215,8 +215,8 @@

Overall Summary

Neighborhood Summary

The table below summarizes ACVs, screening decision, race, and demographic information by neighborhood. The table can be sorted by clicking on the column name or searched using the search box.

-
- +
+

Neighborhood Maps

The maps below are interactive and can be panned and zoomed. Clicking on a neighborhood will provide a pop-up with more information about that neighborhood.

@@ -224,12 +224,12 @@

Neighborhood Maps

ACVs per 1000 Children

The two maps below show the ACV Rate (number of acvs per 1000 children) by neighborhood and by race.

-
- +
+
-
- +
+
@@ -254,12 +254,12 @@

ACVs per 1000 Children

Fraction of ACVs Screened In

The two maps below show the Fraction of ACVs Screened In (number of ACVs that were screened in / number of ACVs) by neighborhood and by race.

-
- +
+
-
- +
+