gen_random_table: Generate a temp table in the database holding a random set of...

View source: R/gen_random_table.R

gen_random_tableR Documentation

Generate a temp table in the database holding a random set of ids

Description

This function enables the user to generate a temporary table in the database that will persist for this connection/session, and that can be utilized in subsequent queries, in order to consistently restrict to that subset. This may be helpful for users to execute an analytic pipeline on a random set of ids.

Usage

gen_random_table(
  table,
  idvars,
  schema = "dbo",
  size = 1000,
  filter = NULL,
  seed = NULL,
  engine = default_engine
)

Arguments

table

string table name to query

idvars

vector of string column names that define uniqueness on the table (i.e. the primary key)

schema

name of schema (default "dbo")

size

number of rows to return (default=1000)

filter

string 'WHERE' clause to further restrict the selection

seed

integer seed for reproducibility; if no seed is provided, a non-reproducible temp table will be produced

engine

a dbConnect connection object; by default will look in namespace for default_engine

Value

a string name of the temporary table created

Examples

rnduids <- gen_random_table(table= "patient", idvars = "osler_id", size = 1000, seed=123)
rnduids <- gen_random_table(table= "patient", idvars = "osler_id", size = 100, seed=87634)
rnduids <- gen_random_table(table= "patient", idvars = "osler_id", filter = "WHERE gender = 'Male'", size = 100, seed=87634)

lmullany/pmap_utilities documentation built on July 30, 2023, 8:54 a.m.