Add File Information From File Database
add_file_info(data)
data | data frame with column |
---|
data frame data
with additional columns folder_path
and file_name
# Define some paths paths <- c( "/very/long/path/very_long_file_name_1", "/very/long/path/very_long_file_name_2", "/very/long/path/very_long_file_name_3" ) # Create a "file database" from the paths file_db <- kwb.file::to_file_database(paths, remove_common_base = FALSE) # Create a data frame that relates some information to the files. # Use the file identifier instead of the full name to keep the data clean (df <- kwb.utils::noFactorDataFrame( file_id = file_db$files$file_id, value = seq_along(paths) ))#> file_id value #> 1 file_01 1 #> 2 file_02 2 #> 3 file_03 3# Store the file database in the attribute "file_db" df <- structure(df, file_db = file_db) # Restore the full file paths add_file_info(df)#> file_id folder_path file_name value #> 1 file_01 /very/long/path very_long_file_name_1 1 #> 2 file_02 /very/long/path very_long_file_name_2 2 #> 3 file_03 /very/long/path very_long_file_name_3 3