save_query: save_query saves connectR's sql to string for tbl, and...

Description Usage Arguments Value Examples

Description

Allows to save connectR's sql query in local file and save to a string for further tbl's. NOTE: save_query will only work with lazy evaluation objects.

Usage

1
save_query(x, save_sql = FALSE, path = NULL, name = NULL, type = NULL)

Arguments

x:

Lazy evaluation object. Object created from the function 'tbl'.

save_sql:

Saves connectR sql when set to 'TRUE', default set to 'FALSE'.

path:

Path to save file, default set to work directory 'getwd()'.

name:

Name of the file, default set to "connectR_sql". Name is only needed and file type is not needed.

type:

File type for saving local file for example '.txt', defaults to '.SQL'.

Value

Returns string format of connectR's sql, and optional save to local file.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#Save lazy evaluation sql to a string
   tbl(post,sql("SELECT * FROM
                 CALENDAR")) %>%
   group_by(ACCOUNT_YEAR_WEEK,
            SEASON) %>%
   summarise(WEEK_ENDING=max(CAL_DATE)) %>%
   save_query ->SQL
#Uses sql string for further lazy_evaluation querying
   tbl(post,sql(SQL))

#Save lazy evaluation sql to default location `getwd()`
#with default name `connectR_sql`
   tbl(post,sql("SELECT * FROM
                 CALENDAR")) %>%
   group_by(ACCOUNT_YEAR_WEEK,
            SEASON) %>%
   summarise(WEEK_ENDING=max(CAL_DATE)) %>%
   save_query(save_query=TRUE)

#Save lazy evaluation sql to default location `C:/R_CODE`
#with default name `connectR_sql`
   tbl(post,sql("SELECT * FROM
                 CALENDAR")) %>%
   group_by(ACCOUNT_YEAR_WEEK,
            SEASON) %>%
   summarise(WEEK_ENDING=max(CAL_DATE)) %>%
   save_query(save_query=TRUE, path="C:/R_CODE")

#Save lazy evaluation sql to default location `C:/R_CODE`
#with name `Test_sql`
   tbl(post,sql("SELECT * FROM
                 CALENDAR")) %>%
   group_by(ACCOUNT_YEAR_WEEK,
            SEASON) %>%
   summarise(WEEK_ENDING=max(CAL_DATE)) %>%
   save_query(save_query=TRUE, path="C:/R_CODE", name="Test_sql")

#Save lazy evaluation sql to default location `C:/R_CODE`
#with name `Test_sql` and type ".txt" text file.
   tbl(post,sql("SELECT * FROM
                 CALENDAR")) %>%
   group_by(ACCOUNT_YEAR_WEEK,
            SEASON) %>%
   summarise(WEEK_ENDING=max(CAL_DATE)) %>%
   save_query(save_query=TRUE, path="C:/R_CODE", name="Test_sql",type=".txt")

DyfanJones/connectR documentation built on May 23, 2019, 10:32 p.m.