This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
This is how you access Snowflake, taking advantage of authentication
driver <- "dnz-economics-sf" #The name in OBDC 64 bit connection, a user DSN that points to SnowflakeDSIIDriver
database <- "SANDPIT_01"
schema <- "PLATEMETERS"
warehouse <- "COMPUTE_WH"
con <- DBI::dbConnect(odbc::odbc(),
driver,
database=database,
schema=schema,
warehouse=warehouse
)
dbListFields(con, "READINGS")
## [1] "READINGID" "FARMID" "PADDOCKID" "WALKID" "HEIGHT"
## [6] "LATITUDE" "LONGITUDE" "ELEVATION" "PLATEMETERID" "DATETIME"
readings <- dbReadTable(con, "READINGS")
dbListFields(con, "WALKS")
## [1] "WALKID" "FARMID" "DATESTART"
## [4] "STOCKCOUNT" "DAILYCONSUMPTIONRATE" "COLLECTORNAME"
## [7] "ROTATIONDAYS" "RESIDUAL" "ACTIVE"
walks <- dbReadTable(con, "WALKS")
# head(readings)
# readings
readings <- readings %>%
filter(!is.na(LONGITUDE)) %>%
filter(LONGITUDE != 0)
readings_sf <- st_as_sf(readings, coords = c("LONGITUDE", "LATITUDE"), crs = 4326)
readings_sf <- left_join(readings_sf, walks) %>%
mutate(DateTimeNZ = with_tz(as_datetime(DATETIME/1000), "Pacific/Auckland"),
DateStartNZ = with_tz(as_datetime(DATESTART/1000), "Pacific/Auckland"),
DateNZ = as_date(DateStartNZ),
DM = HEIGHT * 28 + 500) %>% #Equation from Paul Edwards
filter(COLLECTORNAME != "Mark") %>%
filter(ELEVATION != 0)
## Joining, by = c("FARMID", "WALKID")
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.