NewGraphEnvironment / fpr

Fish Passage Reporting functions for British Columbia
http://www.newgraphenvironment.com/fpr/
Other
2 stars 2 forks source link

fpr::fpr_import_hab_con should explicitly spell out the column types vs guessing them from what is in the input spreadsheet it is reading. #6

Open NewGraphEnvironment opened 1 year ago

NewGraphEnvironment commented 1 year ago

also see https://github.com/NewGraphEnvironment/fish_passage_elk_2022_reporting/issues/2

NewGraphEnvironment commented 1 year ago

Let’s put it here in copy and paste as tibble::tribble (https://github.com/NewGraphEnvironment/fpr/blob/main/data-raw/xref_names_pscis.R)

NewGraphEnvironment commented 1 year ago

here is the workflow to line this up


#run on a complete set of spreadsheets such as skeena 2021 reporting
import <- fpr::fpr_import_pscis_all() %<% 
bind_rows()

# get the column types as a tibble - might need to do this in two steps
types_tib <- tibble(type = sapply(import, class))

# make a tibble to join to fpr::xref_names_pscis
types_to_join <- bind_cols(names(import) %>% as_tibble(), 
types_tib)

# join to fpr::xref_names_pscis
xref <- left_join(fpr::xref_names_pscis, 
                  types_to_join, 
                  by = c('spdsht' = 'value'))

# paste `xref` this as a tribble into the `xref_names_pscis.R` file

`readr::as.col_spec(import)`  will give us the call to `col_types = ` that we can feed to readxl at the start of the fpr_import_pscis` function
NewGraphEnvironment commented 1 year ago

just as a place to put this here is Simon's commands if we wanted to jse postgres column types using bcdata and python

print([(c['column_name'], c['data_type']) for c in bcdata.get_table_definition('WHSE_FISH.PSCIS_ASSESSMENT_SVW')[1]])