file_version | R Documentation |
Create versioned file names for data places files in a directory that looks like a file
e.g. "c:/temp/data.txt" is a folder "c:/temp/data.txt/data._VS_0001_DT_20230530_152025.txt" is a version of the data in this folder "c:/temp/data.txt/data._VS_0002_DT_20230530_175025.txt is an updated version of the data in this folder
file_version(
path,
increment = F,
note = "",
return_all_versions = F,
update_path = T,
purge_missing_versions = ifelse(increment, T, F),
version_markers = c(version = "VS", date = ""),
version_sep = "_",
version_digits = 3,
version_stamp = format(Sys.time(), "%Y%m%d%H%M%S"),
internal_simple = F
)
path |
name of data file |
increment |
(optional) T/F should function increment to new version |
note |
(optional) string giving details of increment - only with increment =T |
return_all_versions |
(optional) return a data.frame with all versions and details |
purge_missing_versions |
(optional) T/F Delete version information if there is no accompanying files |
version_markers |
(optional) names to use for version number and date in verion |
version_sep |
(optional) character to use in separating version components |
version_digits |
(optional) number of zeros to pad version id |
version_stamp |
(optional) data stamp format codes (or other) to use in version |
internal_simple |
(optional) T/F label internal object using only the version to shorten file length |
A convenient / simple way to track versions of data files. Simply provide the base file name and let this function increment in a folder based on the original file name. All parts and versions of files are visible in the folder with the original extension, but with appended versions. For most data iterations the version details are unneeded, but available easily in the folder if warranted. Just use path = file_version("c:/somepath/somedata.csv") and then something like write.csv(data, path) ... Then to read the data, use the same approach. path = file_version("c:/somepath/somedata.csv") then dat = read.csv(path). If you make a change to the data and want to save it off, then simply path = file_version("c:/somepath/somedata.csv",increment=T) and a new dat = read.csv(path) will provide the updated version and data.
Previously I found myself manually creation versions, vs_here = "V1_202300530" but this was fairly unreliable, and I had references to versions scattered everywhere.
This program is free software but it is provided WITHOUT WARRANTY and with ABSOLUTELY NO GUARANTEE of fitness or functionality for any purpose; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Revision History
1.0 | 5/30/2023 created / implemented |
1.1 | 6/14/2023 add support for folder versioning |
There are two possibilities 1. a character string giving the path to a new file name 2. a data.frame with all versioning details in the version tracking sheet
Some Body <some.body@somewhere.com>
filestamp
#edit on the same file over and over
vs_test1 = file_version("c:/temp/dataNoIncrement.txt" , note="editing on single version", increment=F); vs_test1
writeLines(letters,vs_test1)
file_version("c:/temp/dataNoIncrement.txt" , increment=F , return_all_versions = T)
#update version every time
vs_test2 = file_version("c:/temp/dataIncrement.txt" , note="new version and file every time", increment=T); vs_test2
writeLines(letters,vs_test2)
file_version("c:/temp/dataIncrement.txt" , increment=F , return_all_versions = T)
#create folder version instead of file version
#update every time - into new folder
#first time
vs_test2 = file_version("c:/temp/FVSTest" , note="new version and file every time", increment=T); vs_test2
dir.create(vs_test2)
writeLines(letters,file.path(vs_test2,"letters.txt"))
#second time, but use simple internal naming convention
vs_test2 = file_version("c:/temp/FVSTest" , note="new version and file every time", increment=T, internal_simple=T); vs_test2
dir.create(vs_test2)
writeLines(letters,file.path(vs_test2,"letters.txt"))
#view results
file_version("c:/temp/FVSTest" , increment=F , return_all_versions = T , purge_missing_versions = F)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.