fred: FRED

FRED_connectionR Documentation

FRED

Description

Functions for interacting with FRED, the main CD Research database, stored Azure SQL Server

Usage

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
)

Arguments

uid

character, your network ID. Default is getOption("councilR.uid").

pwd

character, your network password. Default is getOption("councilR.pwd"). For example, "mypwd"

db

character, database name. Default is "CD_RESEARCH_WEB".

prod

logical, whether to pull from the test or production db. Default is TRUE.

table_name

character, which table to pull.

Details

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.

Value

fred_connection() - A S4 Microsoft SQL Server object

import_from_FRED() - Requested table

Note

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").

See Also

Other database functions: emissions_connection(), gis_connection()

Examples

## 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)


Metropolitan-Council/councilR documentation built on March 30, 2024, 2:43 a.m.