extract_table: Extracts a table

Description Usage Arguments Value Note Examples

Description

Performs SQL query to extract a table from a database and can select the lines by using a condition (optional).

Usage

1

Arguments

connection

An object that inherits from the dbConnect() function.

table

A string indicating which table you want to extract the data from.

selection

A string indicating the condition you want to use to select lines in the table (optional). NULL is the default value, if nothing is specified the entire table is returned.

Value

The dataset which was the subject of the extraction, is returned as a data.table object.

Note

It is important to leave spaces in the condition as the string is splitted on this pattern. Look at the next section for examples of valid conditions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Say for example you want to track the activities from the
## Datastorm user in the log table this is how you are going to proceed :

mydb <- DBI::dbConnect(MySQL(), user=username, password=mdp,dbname=nom_base, host=port_hote)
condition <- "userid = 46501"
log_datastorm <- extract_table_by_userid(mydb,"mdl_log",condition)

## Now you want to extract the logs
## since 01/08/2017, this is the code you must run :

condition <- "time >= '2017-08-01'"
logs2015 <- extract_table(mydb,"mdl_log",condition)

## Or you just want every log from the start of the period :

logs <- extract_table(mydb,"mdl_log")

guillaumelf/BarchenPackage documentation built on May 31, 2019, 11:50 p.m.