Learn R Programming

healthcareai (version 1.2.4)

selectData: Pull data into R via an ODBC connection

Description

Select data from an ODBC database and return the results as a data frame.

Usage

selectData(MSSQLConnectionString = NULL, query, SQLiteFileName = NULL,
  randomize = FALSE)

Arguments

MSSQLConnectionString

A string specifying the driver, server, database, and whether Windows Authentication will be used.

query

The SQL query (in ticks or quotes)

SQLiteFileName

A string. If dbtype is SQLite, here one specifies the database file to query from

randomize

Boolean that dictates whether returned rows are randomized

Value

df A data frame containing the selected rows

References

http://healthcareai-r.readthedocs.io

See Also

healthcareai

writeData

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
# This example is specific to SQL Server

# To instead pull data from Oracle see here 
# https://cran.r-project.org/web/packages/ROracle/ROracle.pdf
# To pull data from MySQL see here 
# https://cran.r-project.org/web/packages/RMySQL/RMySQL.pdf
# To pull data from Postgres see here 
# https://cran.r-project.org/web/packages/RPostgreSQL/RPostgreSQL.pdf

connectionString <- '
  driver={SQL Server};
  server=localhost;
  database=SAM;
  trustedConnection=true
  '

query <- '
  SELECT
    A1CNBR
  FROM SAM.dbo.HCRDiabetesClinical
  '

df <- selectData(connectionString, query)
head(df)
# }

Run the code above in your browser using DataLab