https://github.com/cadnza/importTablesMSSQL
Simple R package to import tables from Microsoft SQL Server
https://github.com/cadnza/importTablesMSSQL
Last synced: 5 months ago
JSON representation
Simple R package to import tables from Microsoft SQL Server
- Host: GitHub
- URL: https://github.com/cadnza/importTablesMSSQL
- Owner: cadnza
- Created: 2020-05-19T15:22:28.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-30T16:13:45.000Z (over 3 years ago)
- Last Synced: 2024-08-13T07:12:56.778Z (8 months ago)
- Language: R
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - cadnza/importTablesMSSQL - Simple R package to import tables from Microsoft SQL Server (R)
README
# importTablesMSSQL
 
Simple R package to import tables from Microsoft SQL Server.
## Description
Really a very simple package. `importTablesMSSQL` includes one function of the same name, and it imports tables from SQL Server into the R global environment using the `DBI` package. It's intended for multi-table pulls in such cases that render individual queries unwieldy, but it pulls single tables just fine, too.
## Installation
To install, run the following command in the R console after installing the `devtools` package:
```
devtools::install_github("cadnza/importTablesMSSQL")
```If you don't have `devtools`, you can get it here:
```
install.packages("devtools")
```## Use
`importTablesMSSQL` includes standard documentation that can be called from the R console:
```
?importTablesMSSQL
```## Example
```
# Clear environment except for imported tables ----
tryCatch(
expr=rm(list=ls()[!ls()%in%AdventureWorks.manifest]),
error=function(x)invisible()
)# Get connection info ----
server <- "192.168.0.0"
database <- "AdventureWorks"
username <- keyring::key_list(server)$username# Open connection ----
conn <- DBI::dbConnect(
drv = odbc::odbc(),
Driver = "SQL Server",
Port = 1433,
Server=server,
Database=database,
UID=username,
PWD=keyring::key_get(server,username)
)# Import tables ----
importTablesMSSQL(
conn,
tables=c("Sales.vSalesPerson","Person.vAdditionalContactInfo")
)# View SalesPerson dataframe ----
View(AdventureWorks.Sales.vSalesPerson)
```