-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to create a Zip archive of all results in CSV format
- Loading branch information
1 parent
639d636
commit e515a5a
Showing
11 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# EXPORT | ||
#' @include AllGenerics.R | ||
NULL | ||
|
||
# The -r9X flags specify that the zip command should recursively search | ||
# sub-directories, use maximum compression, and remove depreciated file fields. | ||
# The -j flag allows the file names to be stored rather than the full file path. | ||
#' @export | ||
#' @rdname export | ||
#' @aliases export,MultivariateAnalysis-method | ||
setMethod( | ||
f = "export", | ||
signature = c(object = "MultivariateAnalysis"), | ||
definition = function(object, file, flags = "-r9Xj", ...) { | ||
## Create temporary directory | ||
dir_path <- tempfile(pattern = "export_") | ||
dir.create(path = dir_path) | ||
on.exit(unlink(x = dir_path)) | ||
|
||
## Write results | ||
utils::write.csv( | ||
x = get_data(object), | ||
file = make_file_name(dir_path, "data") | ||
) | ||
utils::write.csv( | ||
x = get_eigenvalues(object), | ||
file = make_file_name(dir_path, "eigenvalues") | ||
) | ||
.export(object, path = dir_path, margin = 1) | ||
.export(object, path = dir_path, margin = 2) | ||
|
||
## Zip | ||
status <- utils::zip(zipfile = file, files = dir_path, flags = flags, ...) | ||
invisible(status) | ||
} | ||
) | ||
|
||
.export <- function(object, path, margin, sup_name = ".sup") { | ||
## Coordinates | ||
coords <- get_coordinates( | ||
x = object, | ||
margin = margin, | ||
principal = TRUE, | ||
sup_name = sup_name | ||
) | ||
|
||
## Contributions | ||
contrib <- get_contributions( | ||
x = object, | ||
margin = margin | ||
) | ||
|
||
## cos2 | ||
cos2 <- get_cos2( | ||
x = object, | ||
margin = margin, | ||
sup_name = sup_name | ||
) | ||
|
||
## Write | ||
utils::write.csv(x = coords, file = make_file_name(path, "coordinates", margin)) | ||
utils::write.csv(x = contrib, file = make_file_name(path, "contributions", margin)) | ||
utils::write.csv(x = cos2, file = make_file_name(path, "cos2", margin)) | ||
|
||
invisible(NULL) | ||
} | ||
|
||
make_file_name <- function(path, name, margin = NULL) { | ||
prefix <- "" | ||
if (!is.null(margin) && margin == 1) prefix <- "row_" | ||
if (!is.null(margin) && margin == 2) prefix <- "col_" | ||
|
||
file_name <- paste0(prefix, name, ".csv") | ||
file_path <- file.path(path, file_name) | ||
|
||
file_path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
\dontrun{ | ||
## Load data | ||
data("iris") | ||
|
||
## Compute principal components analysis | ||
X <- pca(iris) | ||
|
||
## Export results | ||
export(X, file = "results.zip") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.