Skip to contents

format_archive() creates formatted names for archives given some informations on the data contained in archives and the type of format aimed at.

It can be as the reciprocal function of analyse_archive().

Usage

format_archive(x, extension, origin = c("floodam.data", "ign", "version"))

Arguments

x

character, a named character.

extension

character, if given, it will overrule what is in x.

origin

character, default value to "floodam.data". See details.

Value

A vector of formatted names.

Details

x should be a named character where informations used for formatting the result ar stored. If some informations are missing, basically NA will be used, and those NA will be post-treated depending on origin.

If origin is "floodam.data", format_archive() returns archive names formatted with this general scheme: data_precision_scope_date. Missing informations in x produce an adaptation of the scheme. For instance, if nothing is given for "scope" in x or if x["scope"] is "NA", the resulting scheme will be data_precision_date.

If origin is "ign", format_archive() returns names formatted with this scheme: data-type_version_precision_format_projection_scope_date. Missing informations in x are replaced by "".

If origin is "version", format_archive() returns names formatted with this scheme: version_precision_format_projection_scope. Missing informations in x are replaced by ".*". No extension information is used.

If extension is given, the extension is added to be name produced. I no extension is given, x["extension"] will be used if not NA.

Author

Frédéric Grelot

Examples

archive = "ADMIN-EXPRESS-COG_3-1__SHP_RGAF09UTM20_GLP_2022-04-15.7z"
x = analyse_archive(archive)

format_archive(x, origin = "ign")
#> [1] "ADMIN-EXPRESS-COG_3-1__SHP_RGAF09UTM20_GLP_2022-04-15.7z"
archive == format_archive(x, origin = "ign")
#> [1] TRUE

format_archive(x, extension = "rds", origin = "ign")
#> [1] "ADMIN-EXPRESS-COG_3-1__SHP_RGAF09UTM20_GLP_2022-04-15.rds"
format_archive(x, extension = "rds")
#> [1] "admin-express-cog_2022-04-15.rds"
x["precision"] = "commune"
x["scope"] = "D972"
format_archive(x, extension = "rds")
#> [1] "admin-express-cog_commune_D972_2022-04-15.rds"

format_archive(origin = "version")
#> [1] ".*_.*_.*_.*_.*"