export_ext: Export an object

Description Usage Arguments Details Value Examples

View source: R/export.R

Description

Saves data given a directory, file name, and extension, or a full path directly.

Usage

 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
export_ext(
  x = NULL,
  file = deparse(substitute(x)),
  dir = getwd(),
  ext = .guess_ext(x),
  path = file.path(dir, paste0(file, ".", ext)),
  overwrite = TRUE,
  backup = FALSE,
  path_backup = NULL,
  export = TRUE,
  return = TRUE,
  verbose = FALSE,
  ...
)

export_ext_csv(...)

export_ext_rdata(...)

export_ext_rda(...)

export_ext_rds(...)

export_ext_png(...)

export_gg(...)

Arguments

x

data.frame (or matrix) for most formats.

file

character. Bare file (i.e. without folderor extension),

dir

character. Folder name (with a trailing slash).

ext

character. Bare extension (i.e. without a dot). Must be one of valid formats.

path

character. Concatenation of file, dir, and ext,

overwrite

logical.

backup

logical.

path_backup

like path,

export

logical. Indicates whether to actually carry res action. Intended to be used as a "catch all".

return

logical. Relevant ONLY if export == FALSE. Set to TRUE in order to preview what would be rendered.

...

dots. Parameters to pass directly to the internally used export function. Important for explicitly specifying non-default ggplot2::ggsave() parameters, as well as specifying worksheets, etc. for an Excel-based export method.

Details

Object to save must be a data.frame (or matrix) for most formats.

This function is intended to be used in a NSE manner, where the file name is derived from the name of the object passed to the function (via deparse(substitute(x))). export_path() may be a suitable alternative if the user wants to specify the path name directly, although such an action can also be done with this function.

Note that the user may not typically be concerned several arguments, including overwrite, backup, path_backup, export, and return. Nonetheless, these are provided in order to facilitate usage with scripts run using "meta"-parameters that determine what data to export, whether or not to overwrite, etc.

Internally, a distinct method (session::save.session) is used for the RData-type file extension in order to allow for importing of packages. Also, ggplot2 objects are treated in a special manner.

Many supplementary functions, using the format export_ext_*() are provided for convenience. (e.g. export_ext_csv() instead of export_ext(..., ext = 'csv').

Value

character. Path.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
if(interactive()){
 # These may be defined elsewhere in a project.
 dir_csv <- "csvs/"
 export_csv <- TRUE
 # ...
 export_ext(iris, ext = "csv", dir = dir_csv, export = export_csv)
 # Or...
 export_ext_csv(iris, dir = dir_csv, export = export_csv)
 }

## End(Not run)

tonyelhabr/teproj documentation built on June 21, 2020, 12:56 p.m.