Helper Functions

library(dht)

Welcome users to DeGAUSS

greeting(
  geomarker_name = "roads",
  version = "0.1",
  description = "calculates proximity and length of nearby major roadways"
)
#> 
#> downloading latest information about images in core library... ■■■■■■■■■■■■■■■■…── Welcome to DeGAUSS! ──
#> downloading latest information about images in core library... ■■■■■■■■■■■■■■■■…
#> downloading latest information about images in core library... ■■■■■■■■■■■■■■■■…• You are using roads, version 0.1
#> downloading latest information about images in core library... ■■■■■■■■■■■■■■■■…• This container returns calculates proximity and length of nearby major
#> roadways
#> downloading latest information about images in core library... ■■■■■■■■■■■■■■■■…• <https://degauss.org/roads>
#> downloading latest information about images in core library... ■■■■■■■■■■■■■■■■…
#> downloading latest information about images in core library... ■■■■■■■■■■■■■■■■…

(Here we supplied values to use in the greeting, but from inside a DeGAUSS container these will be automatically picked up based on the environment variables that capture metadata using just dht::greeting().)

Read in geocoded data

(d <- read_lat_lon_csv('../tests/testthat/my_address_file_geocoded.csv',
sf = T, project_to_crs = 5072))
#> ℹ loading input file...
#> downloading latest information about images in core library...
#> ■■■■■■■■■■■■■■■■…
#> # A tibble: 5 × 6
#>            id   lat   lon start_date end_date  .row
#>         <dbl> <dbl> <dbl> <chr>      <chr>    <int>
#> 1 55001310120  NA    NA   6/11/20    6/18/20      1
#> 2 55000100280  39.2 -84.6 3/1/17     3/8/17       2
#> 3 55000100281  39.3 -84.5 1/30/12    2/6/12       3
#> 4 55000100282  39.2 -84.4 12/1/20    12/8/20      4
#> 5 55000100283  39.2 -84.4 4/8/19     4/15/19      5

Returns a list with two elements – the raw data and tibble nested on row (to prevent calculations with duplicate lat/lon).

Check that required columns are present

check_for_column(d, 'lat', d$lat)

Nothing is returned if the column is present. An error is thrown if the column is not present.

check_for_column(d, "nope", d$lat)
#> ✖ no column called nope found in the input file
#> downloading latest information about images in core library...
#> ■■■■■■■■■■■■■■■■…
#> Error:

Check for column type

check_for_column(d, 'lat', d$lat, 'numeric')

Again, nothing is returned if the column type matches the desired type. A warning is displayed if the column type does not match the desired type.

check_for_column(d, 'lat', d$lat, 'character')
#> ! lat is of type numeric, not character
#> downloading latest information about images in core library...
#> ■■■■■■■■■■■■■■■■…

Check that dates are read in correctly/reformat dates

check_dates(c('1/1/21', '1/2/21', '1/3/21'))
#> [1] "2021-01-01" "2021-01-02" "2021-01-03"

If dates are in slash (1/1/21) or ISO (2021-01-01) format, they are returned in ISO format. If dates are in another format, a helpful error message is generated.

check_dates(c('1/1/2021', '1/2/2021', '1/3/2021'))
#> [1] "2021-01-01" "2021-01-02" "2021-01-03"

Write geomarker output file

Unnests the tibble created with read_lat_lon_csv() and merges back to raw data, then writes the output csv with container name and version appended to filename.

write_geomarker_file(d = d, 
                     raw_data = d, 
                     filename = 'tests/my_address_file_geocoded.csv', 
                     geomarker_name = 'roads', 
                     version = '0.1')

From inside of a DeGAUSS container, where the environment variables that capture metadata are available, this can be accomplished with just:

write_geomarker_file(d = d, raw_data = d, filename = opt$filename)