% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_tables.R
\name{add_exposure}
\alias{add_exposure}
\title{Add exposure simulation data}
\usage{
add_exposure(GT, df, location = "FIPS", substance = "casn", route = "route")
}
\arguments{
\item{GT}{GeoTox object.}

\item{df}{Data frame with exposure simulation data.}

\item{location}{Column name(s) in \code{df} that contain location identifier(s)
(default "FIPS").}

\item{substance}{Column name(s) in \code{df} that contain substance identifier(s)
(default "casn").}

\item{route}{Column name in \code{df} that contains route identifier (default
"route").}
}
\value{
The same GeoTox object, invisibly.
}
\description{
Create or add to the 'exposure' table in a GeoTox database.
}
\details{
The simulation data must contain columns for exposure mean and standard
deviation (default "mean" and "sd", respectfully), at least one column
containing location information (default "FIPS"), at least one column
containing substance information (default "casn"), and one column containing
route information (default "route"). The exposure data is used by
\code{\link[=simulate_exposure]{simulate_exposure()}} to generate external exposure concentration samples for
each location.

The \code{location} and \code{substance} inputs can be named vectors to specify
multiple identifier columns in \code{df}. For example, \code{substance = c(casn = "casn", name = "chnm")} would indicate that \code{df} contains both CAS numbers
and chemical names for substances. The \code{name = "chnm"} part would rename the
"chnm" column in \code{df} to "name" in the 'substance' table.
}
\examples{
# Example exposure simulation data
exposure_df <- tibble::tribble(
  ~FIPS, ~casn, ~route, ~mean, ~sd,
  10000, "00-00-1", "inhalation", 10, 1,
  10000, "00-00-2", "inhalation", 20, 1,
  20000, "00-00-1", "inhalation", 30, 1,
  20000, "00-00-2", "inhalation", 40, 1
)

# Add exposure simulation data to GeoTox database
GT <- GeoTox() |> add_exposure(exposure_df)

# Open a connection to GeoTox database
con <- get_con(GT)

# Look at created tables
dplyr::tbl(con, "exposure") |> dplyr::collect()
dplyr::tbl(con, "location") |> dplyr::collect()
dplyr::tbl(con, "substance") |> dplyr::collect()
dplyr::tbl(con, "route") |> dplyr::collect()

# Add another substance with a new field and route
exposure_df <- tibble::tribble(
  ~FIPS, ~casn, ~chnm, ~route, ~mean, ~sd,
  10000, "00-00-3", "chem3", "drinking", 100, 1,
  20000, "00-00-3", "chem3", "drinking", 200, 1
)
GT |> add_exposure(exposure_df, substance = c(casn = "casn", name = "chnm"))

# Look at updated tables

dplyr::tbl(con, "exposure") |> dplyr::collect()

dplyr::tbl(con, "substance") |> dplyr::collect()

dplyr::tbl(con, "route") |> dplyr::collect()

# Clean up example
DBI::dbDisconnect(con)
file.remove(GT$db_info$dbdir)
}
\seealso{
\code{\link[=simulate_exposure]{simulate_exposure()}}
}
