Skip to content

Load R data frames into MS SQL Server databases and modify database tables with R

License

Notifications You must be signed in to change notification settings

ScotGovAnalysis/RtoSQLServer

Repository files navigation

RtoSQLServer

GitHub release (latest by date) R-CMD-check

Load R data frames into an MS SQL Server database and modify MS SQL Server tables with R. For help documentation, see the package website.

Installation

If you are working within the Scottish Government, the package can be installed in the same way as other R packages internally.

Alternatively, the package can be installed directly from Github or locally from zip.
To install directly from GitHub:

remotes::install_github("DataScienceScotland/rtosqlserver", upgrade = "never")

If the above does not work, install from manual download:

  1. Download the zip of the repository from GitHub.
  2. Save the downloaded zip to a specific directory (e.g. C:/temp).
  3. Install with this command specifying the path to the downloaded zip:
remotes::install_local("C:/temp/RtoSQLServer-main.zip", upgrade="never")

Functionality

As well as loading R dataframes into SQL Server databases, functions are currently available to:

Example

See Get started for examples of the main functionality.

# Loading data frame example
library(RtoSQLServer)

# Make a test dataframe with n rows
test_n_rows <- 123456
test_df <- data.frame(a = rep("a", test_n_rows), b = rep("b", test_n_rows))

# Set database connection details:
server <- "server\\instance"
database <- "my_database_name"
schema <- "my_schema_name"

# Write the test dataframe to a SQL Server table
write_dataframe_to_db(
  server = server,
  database = database,
  schema = schema,
  table_name = "test_r_tbl",
  dataframe = test_df
)