df_to_sql: Dataframe to SQL

View source: R/df_to_sql.R

df_to_sqlR Documentation

Dataframe to SQL

Description

DataFrame to SQL; Write your DataFrame or Tibble directly to SQL from R This wrapper function allows for the easy movement of your computed results in R to a SQL Database for saving. The function uses a ODBC driver to establish a connection. You will need to select a Database that your user has write-access to. The user credentials are the same as your OS login details; as such this function will most likely only work from you work computer.

Usage

df_to_sql(df, driver, server, database, sql_table_name, overwrite = FALSE, ...)

Arguments

df

A 'dataFrame' or 'tibble' ie PopHealthData.

driver

A driver for database ie "SQL Server"; must be passed in quotation.

server

The unique name of your database server; must be passed in quotation.

database

The name of the database to which you will write 'df'; must be passed in quotation.

sql_table_name

The name that 'df' will be referred to in SQL database; must be passed in quotation.

overwrite

If there is a SQL table with the same name whether it will be overwritten; defaults to FALSE.

...

Function forwarding for additional functionality.

Value

A message confirming that a new table has been created in a SQL 'database'.

Examples

## Not run: 
library(odbc)
library(DBI)
health_data <- SangerTools::PopHealthData
df_to_sql(
  df = health_data,
  driver = "SQL SERVER",
  database = "DATABASE",
  sql_table_name = "New Table Name",
  overwrite = FALSE
)

## End(Not run)

ald0405/SangerTools documentation built on Feb. 20, 2024, 3:11 p.m.