Skip to contents

delete_agency() deletes an existing agency in the agency lookup table

Usage

delete_agency(con, agency_id)

Arguments

con

A DBI connection object obtained from DBI::dbConnect()

agency_id

A numeric ID for the targeted agency get_agencies

Details

Note: If an agency has been associated with a permit record, then the database restricts deleting this agency. You must first update those records with a new agency before reattempting to delete the agency. Consider using the update_agency_status function if you are wanting to retire an agency while retaining its value for historic records.

See also

Other agency functions: add_agency(), get_agencies(), update_agency(), update_agency_status()

Examples

# example database connection
cfg <- config::get()
con <- DBI::dbConnect(RPostgres::Postgres(),
                      dbname = cfg$dbname,
                      host = cfg$host,
                      port = cfg$port,
                      user = cfg$username,
                      password = cfg$password)
#> Error: connection to server at "localhost" (::1), port 5432 failed: Connection refused (0x0000274D/10061)
#> 	Is the server running on that host and accepting TCP/IP connections?
#> connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused (0x0000274D/10061)
#> 	Is the server running on that host and accepting TCP/IP connections?

all_agencies <- get_agencies(con)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'dbObj' in selecting a method for function 'dbIsValid': object 'con' not found
View(all_agencies) # to view the ID of the agency needing deletion
#> Error in eval(expr, envir, enclos): object 'all_agencies' not found

delete_agency(con, 4)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'dbObj' in selecting a method for function 'dbIsValid': object 'con' not found