
sirfunctions i/o handler
sirfunctions_io.RdManages read/write/list/create/delete functions for sirfunctions. This function is adapted from tidypolis_io.
Usage
sirfunctions_io(
io,
default_folder = "GID/PEB/SIR",
file_loc,
obj = NULL,
edav = TRUE,
azcontainer = suppressMessages(sirfunctions::get_azure_storage_connection()),
full_names = T,
...
)Arguments
- io
strThe type of operation to use. Valid values include:"read": reads data from the specifiedfile_path."write": writes data to the specifiedfile_path."list": lists the files in the specifiedfile_path."exists.dir": determines whether a directory is present."exists.file": determines whether a file is present."create.dir": creates a directory to the specifiedfile_path."delete": deletes a file in the specifiedfile_path."delete.dir": deletes a folder in the specifiedfile_path.
- default_folder
strThe default folder to use. Defaults to"GID/PEB/SIR.- file_loc
strPath of file relative to thedefault_folder.- obj
strObject to be loaded into EDAV- edav
logicalWhether the function should interact with the EDAV environment. Defaults toTRUE, otherwise, interacts with files locally.- azcontainer
Azure containerA container object returned byget_azure_storage_connection().- full_names
logicalIfio="list", include the full reference path. DefaultTRUE.- ...
Optional parameters that work with
readr::read_delim()orreadxl::read_excel().
Value
Conditional on io. If io is "read", then it will return a tibble. If io is "list", it will return a
list of file names. Otherwise, the function will return NULL. exists.dir and exists.file will return a logical.
Examples
if (FALSE) { # \dontrun{
df <- sirfunctions_io("read", file_loc = "df1.csv") # read file from EDAV
# Passing parameters that work with read_csv or read_excel, like sheet or skip.
df2 <- sirfunctions_io("read", file_loc = "df2.xlsx", sheet = 1, skip = 2)
list_of_df <- list(df_1 = df, df_2 = df)
# Saves df to the test folder in EDAV
sirfunctions_io("write", file_loc = "Data/test/df.csv", obj = df)
# Saves list_of_df as an Excel file with multiple sheets.
sirfunctions_io("write", file_loc = "Data/test/df.xlsx", obj = list_of_df)
sirfunctions_io("exists.dir", "Data/nonexistentfolder") # returns FALSE
sirfunctions_io("exists.file", file_loc = "Data/test/df1.csv") # returns TRUE
sirfunctions_io("create", "Data/nonexistentfolder") # creates a folder called nonexistentfolder
sirfunctions_io("list") # list all files from the default directory
} # }