FRED_connection | R Documentation |
Functions for interacting with FRED, the main CD Research database, stored Azure SQL Server
FRED_connection(
uid = getOption("councilR.uid"),
pwd = getOption("councilR.pwd"),
db = "CD_RESEARCH_WEB",
prod = TRUE
)
fred_connection(
uid = getOption("councilR.uid"),
pwd = getOption("councilR.pwd"),
db = "CD_RESEARCH_WEB",
prod = TRUE
)
import_from_FRED(
table_name,
uid = getOption("councilR.uid"),
pwd = getOption("councilR.pwd"),
db = "CD_RESEARCH_WEB",
prod = TRUE
)
import_from_fred(
table_name,
uid = getOption("councilR.uid"),
pwd = getOption("councilR.pwd"),
db = "CD_RESEARCH_WEB",
prod = TRUE
)
uid |
character, your network ID.
Default is |
pwd |
character, your network password.
Default is |
db |
character, database name. Default is |
prod |
logical, whether to pull from the test or production db.
Default is |
table_name |
character, which table to pull. |
Both "FRED" and "fred" capitalization are supported.
fred_connection()
creates an S4 Microsoft SQL Server object for FRED.
This function will not automatically close the connection, so take
care to use DBI::dbDisconnect()
once you are done.
import_from_fred()
imports a given table from FRED. The connection will
be automatically closed after the table is imported.
fred_connection()
- A S4 Microsoft SQL Server object
import_from_FRED()
- Requested table
See vignette("Options")
to review package options.
You must be set up with the appropriate database drivers to use these functions.
Windows users need ODBC with Microsoft SQL. Contact IS support for ODBC installation.
Mac users need unixodbc
, freetds
, and properly configured odbc.ini
.
See instructions in the
onboarding guide
and contact package maintainer for assistance.
These functions rely on {rlang}
internal functions.
Further examples can be found in vignette("Databases")
.
Other database functions:
emissions_connection()
,
gis_connection()
## Not run:
library(councilR)
library(DBI)
# set options if you haven't already
options(
councilR.uid = "mc\\you",
councilR.pwd = "mypwd"
)
# create connection
conn <- FRED_connection(prod = FALSE)
# pull table using SQL
DBI::dbGetQuery(conn, "SELECT * FROM GQ_UNIT WHERE UNIT_ZIP = 55104")
# disconnect
DBI::dbDisconnect(conn)
# import a specific table, with no additional SQL logic
import_from_FRED(table_name = "GQ_UNIT", prod = FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.