Create an exposure_occurrence (exposure) table from a variable source id
Source:R/createExposure.R
createExposure.Rd
Create an exposure_occurrence (exposure) table from a variable source id
Arguments
- connectionDetails
(list) An object of class connectionDetails as created by the createConnectionDetails function
- variableSourceId
(integer) The variable source id of the variable to create an exposure table for
- locationImport
(data.frame) A data frame with columns location_id and geometry. Represents the geocoded locations
Value
(data.frame) An OMOP CDM exposure_occurrence table for the specified variable source id and locations
Details
This function creates an exposure_occurrence table for a given variable source id and geocoded locations. The exposure_occurrence table is created by joining the variable table to the geom table and then joining the geom table to the geocoded locations. The exposure_occurrence table is then created by selecting the relevant columns from the variable table and the geocoded locations.
The locationImport data frame should have columns location_id and geometry. The location_id column should be an integer representing the location_id of the geocoded location. The geometry column should be a binary representation of the geometry of the geocoded location:
locationImport <- read.csv('geocoded_location_snippet.csv', sep="|", header=FALSE)
locationImport <- dplyr::rename(locationImport, location_id=1, lat=11, lon=12)
locationImport <- dplyr::mutate(locationImport,
location_id=as.integer(location_id),
lat=as.numeric(lat),
lon=as.numeric(gsub("[\\n]", "", lon)))
locationImport <- dplyr::filter(locationImport, !is.na(lat) & !is.na(lon))
locationImport <- locationImport_sf <- sf::st_as_sf(locationImport, coords=c('lon', 'lat'), crs=4326)
locationImport <- dplyr::select(locationImport, location_id, geometry)
locationImport <- data.frame(locationImport)
locationImport$geometry <-
sf::st_as_binary(locationImport$geometry, EWKB = TRUE, hex = TRUE)
#> head(locationImport)
#=> location_id geometry
#=> 1 1 0101000020e610000072230d5ff6c351c000023164d0284540
#=> 2 2 0101000020e61000007222df852d8a52c0978b9d95594e4440
#=> 3 3 0101000020e610000076319xaa4ae351c0ba0a73cc43124540
#=> 4 4 0101000020e61000001d90fdfc97bc51c08a05bea2dbdd4440
Examples
if (FALSE) { # \dontrun{
# Create exposure_occurrence table for a given variable
variableSourceId <- 1 # Percentile Percentage of persons below poverty estimate
locationImport <- data.frame(location)
exposure_occurrence <- createExposure(connectionDetails, variableSourceId, locationImport)
} # }