Writes a file to a given location. If to
does not exist, it is
created, and if filename
is not provided, a default standardized name is chosen.
Usage
write_standardized_df(
df,
to,
filename,
write = TRUE,
return_path = ifelse(write, FALSE, TRUE),
verbose = TRUE,
logger = NA
)
Arguments
- df
The standardized file
- to
The target folder to copy data in. If it does not exist, will be created.
- filename
The name to give to the file.
- write
if TRUE (default), will write the
df
in theto
folder, anddf
will be namedfilename
.- return_path
Should the path be returned?
- verbose
Should messages be displayed when creating a folder/file?
- logger
a
log4r
logger
object if you want logging (can be created withcreate_logger
), elseNA
.
Value
Writes the file to the folder to/filename
.
Also returns the path to/filename
if return_path == TRUE
.
Examples
std_dat <- standardize_snapshot_df(zooniverse, standard)
#> Initial file: 24 columns, 100 rows.
#> Standardizing columns
#> Standardizing dates/times
#> Fill capture info
#> Cleaning location/camera, species and columns values
#> Final file: 27 columns, 100 rows. Here is a sneak peek:
#> locationID cameraID season roll eventID snapshotName eventDate eventTime
#> APN APN_13U 1 1 APN_13U#1#50 kudu 2017-07-25 02:15:22
#> APN APN_6U 1 1 APN_6U#1#40 steenbok 2017-07-17 08:56:18
#> APN APN_6U 1 2 APN_6U#2#5 zebraburchells 2017-08-07 04:49:29
#> APN APN_DW 1 2 APN_DW#2#94 impala 2017-07-06 18:16:19
#> APN APN_DW 1 1 APN_DW#1#210 zebraburchells 2017-07-21 18:09:16
# Don't write data
write_standardized_df(std_dat,
to = "/home/lnicvert/Documents/PhD/Snapshot/data/2_standardized_data",
write = FALSE)
#> [1] "/home/lnicvert/Documents/PhD/Snapshot/data/2_standardized_data/APN_S1_R1-2.csv"
# Don't write data and use custom name
write_standardized_df(std_dat,
to = "/home/lnicvert/Documents/PhD/Snapshot/data/2_standardized_data",
filename = "myname.csv",
write = FALSE)
#> [1] "/home/lnicvert/Documents/PhD/Snapshot/data/2_standardized_data/myname.csv"
# Write file to temporary location
write_standardized_df(std_dat,
to = tempdir())
#> Writing file /tmp/Rtmp3MYUYp/APN_S1_R1-2.csv ---