From ccdda46175ebe45281ba58b97e9d75a7f12f4fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Thu, 8 May 2025 12:39:18 +0200 Subject: [PATCH 1/9] Exporting metrics --- R/export.R | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 R/export.R diff --git a/R/export.R b/R/export.R new file mode 100644 index 00000000..a5377bf5 --- /dev/null +++ b/R/export.R @@ -0,0 +1,39 @@ +serialize_with_attributes <- function(x) { + if (is.list(x) && !is.null(names(x))) { + result <- list() + for (n in names(x)) { + result[[n]] <- serialize_with_attributes(x[[n]]) + } + return(result) + } + + # For atomic or S3 elements with attributes + val <- unclass(x) + attrs <- attributes(x) + + # Sanitize attributes (no S3 objects inside) + if (!is.null(attrs)) { + for (a in names(attrs)) { + if (inherits(attrs[[a]], "AsIs") || is.factor(attrs[[a]])) { + attrs[[a]] <- as.character(attrs[[a]]) + } else if (!is.atomic(attrs[[a]])) { + attrs[[a]] <- unclass(attrs[[a]]) + } + } + } + + list( + value = val, + attributes = attrs + ) +} + + +export_json <- function(metrics, file = "PACKAGES.json") { + metrics_serialized <- serialize_with_attributes(metrics) + jsonlite::write_json(metrics_serialized, path = file, pretty = TRUE, auto_unbox = FALSE) +} + +export_dcf <- function(metrics, file = "PACKAGES") { + write.dcf(metrics, file = file) +} From c097821c1278e276b705123f9b04d47326ffa670 Mon Sep 17 00:00:00 2001 From: Rabii Bouhestine Date: Mon, 12 May 2025 09:58:05 +0000 Subject: [PATCH 2/9] add pkg_metric_export --- R/pkg_metric_export.R | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 R/pkg_metric_export.R diff --git a/R/pkg_metric_export.R b/R/pkg_metric_export.R new file mode 100644 index 00000000..14c68e61 --- /dev/null +++ b/R/pkg_metric_export.R @@ -0,0 +1,83 @@ +# Converts snake_case to PascalCase +to_pascal_case <- function(x) { + words <- strsplit(x, "_")[[1]] + paste0(toupper(substring(words, 1, 1)), substring(words, 2), collapse = "") +} + +#' Flatten scored metrics to DCF-style key-value pairs +#' +#' `pkg_metric_export()` converts scored package metrics into a flat list of +#' character strings in DCF (Debian Control File) style. Each metric is +#' written as a line in the form `Metric: `, where `` is the +#' PascalCase transformation of the metric name. +#' +#' This is useful for exporting results from `pkg_score()` into formats that +#' require simple key-value structures. +#' +#' @param x A `tbl_df` or `list` returned by `pkg_score()`, containing scored +#' `pkg_metric` values. The input may come from `pkg_score.tbl_df()` (for +#' many packages) or `pkg_score.list_of_pkg_metric()` (for a single package). +#' +#' @return A character vector, where each element is a DCF-style line +#' representing one scored metric (e.g., `"MetricHasNews: 1"`). +#' +#' @examples +#' \dontrun{ +#' # For a single package +#' metrics <- pkg_score(pkg_assess(pkg_ref("riskmetric")))[[1]] +#' pkg_metric_export(metrics) +#' +#' # For a data frame of packages +#' library(dplyr) +#' scores <- pkg_score(pkg_assess(as_tibble(pkg_ref("riskmetric")))) +#' pkg_metric_export(scores[1, ]) # flatten first package's results +#' } +#' +#' @export +pkg_metric_export <- function(x, ...) { + UseMethod("pkg_metric_export") +} + +#' @export +pkg_metric_export.list <- function(x, file = "PACKAGES", ...) { + record <- list() + for (name in names(x)) { + pascal_name <- paste0("Metric", to_pascal_case(name)) + value <- as.character(x[[name]][1]) + record[[pascal_name]] <- value + } + + # Convert to one-row data frame + df <- as.data.frame(record, stringsAsFactors = FALSE) + write.dcf(df, file = file) + df +} + +#' @export +pkg_metric_export.tbl_df <- function(x, file = "PACKAGES", ...) { + x <- x[, setdiff(names(x), "pkg_ref")] + + records <- apply(x, 1, function(row) { + metrics <- as.list(row) + record <- list() + + for (name in names(metrics)) { + value <- as.character(metrics[[name]]) + # Leave Package and Version untouched + if (name %in% c("package", "version")) { + pascal_name <- to_pascal_case(name) + record[[pascal_name]] <- value + } else { + pascal_name <- paste0("Metric", to_pascal_case(name)) + record[[pascal_name]] <- value + } + } + + record + }) + + # Convert to data frame + df <- do.call(rbind.data.frame, lapply(records, as.data.frame, stringsAsFactors = FALSE)) + write.dcf(df, file = file) + df +} From 447b223beb00ae724f73c09d4193ccc51a7ef65f Mon Sep 17 00:00:00 2001 From: Rabii Bouhestine Date: Mon, 12 May 2025 10:08:43 +0000 Subject: [PATCH 3/9] handle NA values in pkg_metric_export --- R/pkg_metric_export.R | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/R/pkg_metric_export.R b/R/pkg_metric_export.R index 14c68e61..37d181ef 100644 --- a/R/pkg_metric_export.R +++ b/R/pkg_metric_export.R @@ -44,7 +44,9 @@ pkg_metric_export.list <- function(x, file = "PACKAGES", ...) { for (name in names(x)) { pascal_name <- paste0("Metric", to_pascal_case(name)) value <- as.character(x[[name]][1]) - record[[pascal_name]] <- value + + # Replace NA values with "NA" string + record[[pascal_name]] <- ifelse(is.na(value), "NA", value) } # Convert to one-row data frame @@ -63,9 +65,13 @@ pkg_metric_export.tbl_df <- function(x, file = "PACKAGES", ...) { for (name in names(metrics)) { value <- as.character(metrics[[name]]) - # Leave Package and Version untouched + + # Replace NA values with "NA" string + value <- ifelse(is.na(value), "NA", value) + + # Leave Package and Version untouched, but ensure CamelCase if (name %in% c("package", "version")) { - pascal_name <- to_pascal_case(name) + pascal_name <- paste0(toupper(substring(name, 1, 1)), substring(name, 2)) record[[pascal_name]] <- value } else { pascal_name <- paste0("Metric", to_pascal_case(name)) From 866ac00ac24d8968bffed1f7a5f51c4c356bdbc1 Mon Sep 17 00:00:00 2001 From: Rabii Bouhestine Date: Thu, 29 May 2025 08:37:35 +0000 Subject: [PATCH 4/9] delete unused code --- R/export.R | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 R/export.R diff --git a/R/export.R b/R/export.R deleted file mode 100644 index a5377bf5..00000000 --- a/R/export.R +++ /dev/null @@ -1,39 +0,0 @@ -serialize_with_attributes <- function(x) { - if (is.list(x) && !is.null(names(x))) { - result <- list() - for (n in names(x)) { - result[[n]] <- serialize_with_attributes(x[[n]]) - } - return(result) - } - - # For atomic or S3 elements with attributes - val <- unclass(x) - attrs <- attributes(x) - - # Sanitize attributes (no S3 objects inside) - if (!is.null(attrs)) { - for (a in names(attrs)) { - if (inherits(attrs[[a]], "AsIs") || is.factor(attrs[[a]])) { - attrs[[a]] <- as.character(attrs[[a]]) - } else if (!is.atomic(attrs[[a]])) { - attrs[[a]] <- unclass(attrs[[a]]) - } - } - } - - list( - value = val, - attributes = attrs - ) -} - - -export_json <- function(metrics, file = "PACKAGES.json") { - metrics_serialized <- serialize_with_attributes(metrics) - jsonlite::write_json(metrics_serialized, path = file, pretty = TRUE, auto_unbox = FALSE) -} - -export_dcf <- function(metrics, file = "PACKAGES") { - write.dcf(metrics, file = file) -} From 1ba658e6ae9bac900134c1e399bb40fd842500ac Mon Sep 17 00:00:00 2001 From: Rabii Bouhestine Date: Thu, 29 May 2025 08:42:00 +0000 Subject: [PATCH 5/9] update docs --- DESCRIPTION | 2 +- NAMESPACE | 3 +++ man/pkg_assess.Rd | 26 +++++++++++++------------- man/pkg_metric_export.Rd | 40 ++++++++++++++++++++++++++++++++++++++++ man/riskmetric.Rd | 2 +- 5 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 man/pkg_metric_export.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 52df64ae..62dd5d70 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,6 +45,6 @@ Suggests: testthat, webmockr, jsonlite -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 VignetteBuilder: knitr Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index ad58cbcf..212748f0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -76,6 +76,8 @@ S3method(pillar_shaft,pkg_metric_error) S3method(pkg_assess,list_of_pkg_ref) S3method(pkg_assess,pkg_ref) S3method(pkg_assess,tbl_df) +S3method(pkg_metric_export,list) +S3method(pkg_metric_export,tbl_df) S3method(pkg_score,list_of_pkg_metric) S3method(pkg_score,tbl_df) S3method(print,pkg_ref) @@ -116,6 +118,7 @@ export(get_assessments) export(metric_score) export(pkg_assess) export(pkg_metric) +export(pkg_metric_export) export(pkg_ref) export(pkg_score) export(score_error_NA) diff --git a/man/pkg_assess.Rd b/man/pkg_assess.Rd index a5b7733c..fd7c810b 100644 --- a/man/pkg_assess.Rd +++ b/man/pkg_assess.Rd @@ -43,25 +43,25 @@ assessment applied. \section{Assessment function catalog}{ \describe{ -\item{\code{\link{assess_last_30_bugs_status}}}{vector indicating whether BugReports status is closed} \item{\code{\link{assess_covr_coverage}}}{Package unit test coverage} -\item{\code{\link{assess_size_codebase}}}{number of lines of code base} -\item{\code{\link{assess_export_help}}}{exported objects have documentation} -\item{\code{\link{assess_r_cmd_check}}}{Package check results} -\item{\code{\link{assess_dependencies}}}{Package dependency footprint} -\item{\code{\link{assess_reverse_dependencies}}}{List of reverse dependencies a package has} -\item{\code{\link{assess_license}}}{software is released with an acceptable license} -\item{\code{\link{assess_has_maintainer}}}{a vector of associated maintainers} +\item{\code{\link{assess_has_news}}}{number of discovered NEWS files} \item{\code{\link{assess_remote_checks}}}{Number of OS flavors that passed/warned/errored on R CMD check} +\item{\code{\link{assess_news_current}}}{NEWS file contains entry for current version number} +\item{\code{\link{assess_r_cmd_check}}}{Package check results} \item{\code{\link{assess_exported_namespace}}}{Objects exported by package} -\item{\code{\link{assess_has_website}}}{a vector of associated website urls} -\item{\code{\link{assess_downloads_1yr}}}{number of downloads in the past year} -\item{\code{\link{assess_has_news}}}{number of discovered NEWS files} \item{\code{\link{assess_has_vignettes}}}{number of discovered vignettes files} -\item{\code{\link{assess_has_examples}}}{proportion of discovered function files with examples} +\item{\code{\link{assess_export_help}}}{exported objects have documentation} +\item{\code{\link{assess_has_website}}}{a vector of associated website urls} +\item{\code{\link{assess_has_maintainer}}}{a vector of associated maintainers} +\item{\code{\link{assess_last_30_bugs_status}}}{vector indicating whether BugReports status is closed} +\item{\code{\link{assess_size_codebase}}}{number of lines of code base} \item{\code{\link{assess_has_source_control}}}{a vector of associated source control urls} \item{\code{\link{assess_has_bug_reports_url}}}{presence of a bug reports url in repository} -\item{\code{\link{assess_news_current}}}{NEWS file contains entry for current version number} +\item{\code{\link{assess_downloads_1yr}}}{number of downloads in the past year} +\item{\code{\link{assess_reverse_dependencies}}}{List of reverse dependencies a package has} +\item{\code{\link{assess_has_examples}}}{proportion of discovered function files with examples} +\item{\code{\link{assess_dependencies}}}{Package dependency footprint} +\item{\code{\link{assess_license}}}{software is released with an acceptable license} } } diff --git a/man/pkg_metric_export.Rd b/man/pkg_metric_export.Rd new file mode 100644 index 00000000..f0e1217c --- /dev/null +++ b/man/pkg_metric_export.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pkg_metric_export.R +\name{pkg_metric_export} +\alias{pkg_metric_export} +\title{Flatten scored metrics to DCF-style key-value pairs} +\usage{ +pkg_metric_export(x, ...) +} +\arguments{ +\item{x}{A `tbl_df` or `list` returned by `pkg_score()`, containing scored +`pkg_metric` values. The input may come from `pkg_score.tbl_df()` (for +many packages) or `pkg_score.list_of_pkg_metric()` (for a single package).} +} +\value{ +A character vector, where each element is a DCF-style line + representing one scored metric (e.g., `"MetricHasNews: 1"`). +} +\description{ +`pkg_metric_export()` converts scored package metrics into a flat list of +character strings in DCF (Debian Control File) style. Each metric is +written as a line in the form `Metric: `, where `` is the +PascalCase transformation of the metric name. +} +\details{ +This is useful for exporting results from `pkg_score()` into formats that +require simple key-value structures. +} +\examples{ +\dontrun{ +# For a single package +metrics <- pkg_score(pkg_assess(pkg_ref("riskmetric")))[[1]] +pkg_metric_export(metrics) + +# For a data frame of packages +library(dplyr) +scores <- pkg_score(pkg_assess(as_tibble(pkg_ref("riskmetric")))) +pkg_metric_export(scores[1, ]) # flatten first package's results +} + +} diff --git a/man/riskmetric.Rd b/man/riskmetric.Rd index 87bcdb8f..366392f1 100644 --- a/man/riskmetric.Rd +++ b/man/riskmetric.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/riskmetric-package.R \docType{package} \name{riskmetric} -\alias{riskmetric} \alias{riskmetric-package} +\alias{riskmetric} \title{riskmetric} \description{ Facilities for assessing R packages against a number of metrics to help From b7278c9d97faf3eec58f4f220492fbf5728fd576 Mon Sep 17 00:00:00 2001 From: Rabii Bouhestine Date: Thu, 29 May 2025 13:19:14 +0000 Subject: [PATCH 6/9] update docstring --- R/pkg_metric_export.R | 1 + man/pkg_metric_export.Rd | 2 ++ 2 files changed, 3 insertions(+) diff --git a/R/pkg_metric_export.R b/R/pkg_metric_export.R index 37d181ef..dbaff7d9 100644 --- a/R/pkg_metric_export.R +++ b/R/pkg_metric_export.R @@ -17,6 +17,7 @@ to_pascal_case <- function(x) { #' @param x A `tbl_df` or `list` returned by `pkg_score()`, containing scored #' `pkg_metric` values. The input may come from `pkg_score.tbl_df()` (for #' many packages) or `pkg_score.list_of_pkg_metric()` (for a single package). +#' @param ... additional arguments unused #' #' @return A character vector, where each element is a DCF-style line #' representing one scored metric (e.g., `"MetricHasNews: 1"`). diff --git a/man/pkg_metric_export.Rd b/man/pkg_metric_export.Rd index f0e1217c..5c7ee983 100644 --- a/man/pkg_metric_export.Rd +++ b/man/pkg_metric_export.Rd @@ -10,6 +10,8 @@ pkg_metric_export(x, ...) \item{x}{A `tbl_df` or `list` returned by `pkg_score()`, containing scored `pkg_metric` values. The input may come from `pkg_score.tbl_df()` (for many packages) or `pkg_score.list_of_pkg_metric()` (for a single package).} + +\item{...}{additional arguments unused} } \value{ A character vector, where each element is a DCF-style line From 23c3f43804989472d73d99f5b17193f162dfc557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Thu, 5 Jun 2025 14:57:27 +0200 Subject: [PATCH 7/9] Documenting pkg_metric_export --- DESCRIPTION | 2 +- NAMESPACE | 3 +++ R/pkg_metric_export.R | 2 +- man/pkg_metric_export.Rd | 40 ++++++++++++++++++++++++++++++++++++++++ man/riskmetric.Rd | 2 +- 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 man/pkg_metric_export.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 52df64ae..62dd5d70 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,6 +45,6 @@ Suggests: testthat, webmockr, jsonlite -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 VignetteBuilder: knitr Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index ad58cbcf..212748f0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -76,6 +76,8 @@ S3method(pillar_shaft,pkg_metric_error) S3method(pkg_assess,list_of_pkg_ref) S3method(pkg_assess,pkg_ref) S3method(pkg_assess,tbl_df) +S3method(pkg_metric_export,list) +S3method(pkg_metric_export,tbl_df) S3method(pkg_score,list_of_pkg_metric) S3method(pkg_score,tbl_df) S3method(print,pkg_ref) @@ -116,6 +118,7 @@ export(get_assessments) export(metric_score) export(pkg_assess) export(pkg_metric) +export(pkg_metric_export) export(pkg_ref) export(pkg_score) export(score_error_NA) diff --git a/R/pkg_metric_export.R b/R/pkg_metric_export.R index 37d181ef..e42e7ab8 100644 --- a/R/pkg_metric_export.R +++ b/R/pkg_metric_export.R @@ -44,7 +44,7 @@ pkg_metric_export.list <- function(x, file = "PACKAGES", ...) { for (name in names(x)) { pascal_name <- paste0("Metric", to_pascal_case(name)) value <- as.character(x[[name]][1]) - + # Replace NA values with "NA" string record[[pascal_name]] <- ifelse(is.na(value), "NA", value) } diff --git a/man/pkg_metric_export.Rd b/man/pkg_metric_export.Rd new file mode 100644 index 00000000..f0e1217c --- /dev/null +++ b/man/pkg_metric_export.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pkg_metric_export.R +\name{pkg_metric_export} +\alias{pkg_metric_export} +\title{Flatten scored metrics to DCF-style key-value pairs} +\usage{ +pkg_metric_export(x, ...) +} +\arguments{ +\item{x}{A `tbl_df` or `list` returned by `pkg_score()`, containing scored +`pkg_metric` values. The input may come from `pkg_score.tbl_df()` (for +many packages) or `pkg_score.list_of_pkg_metric()` (for a single package).} +} +\value{ +A character vector, where each element is a DCF-style line + representing one scored metric (e.g., `"MetricHasNews: 1"`). +} +\description{ +`pkg_metric_export()` converts scored package metrics into a flat list of +character strings in DCF (Debian Control File) style. Each metric is +written as a line in the form `Metric: `, where `` is the +PascalCase transformation of the metric name. +} +\details{ +This is useful for exporting results from `pkg_score()` into formats that +require simple key-value structures. +} +\examples{ +\dontrun{ +# For a single package +metrics <- pkg_score(pkg_assess(pkg_ref("riskmetric")))[[1]] +pkg_metric_export(metrics) + +# For a data frame of packages +library(dplyr) +scores <- pkg_score(pkg_assess(as_tibble(pkg_ref("riskmetric")))) +pkg_metric_export(scores[1, ]) # flatten first package's results +} + +} diff --git a/man/riskmetric.Rd b/man/riskmetric.Rd index 87bcdb8f..366392f1 100644 --- a/man/riskmetric.Rd +++ b/man/riskmetric.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/riskmetric-package.R \docType{package} \name{riskmetric} -\alias{riskmetric} \alias{riskmetric-package} +\alias{riskmetric} \title{riskmetric} \description{ Facilities for assessing R packages against a number of metrics to help From a237f50a147a20c48f9427f61ecc8a9887824db1 Mon Sep 17 00:00:00 2001 From: Rabii Bouhestine Date: Mon, 9 Jun 2025 12:41:46 +0000 Subject: [PATCH 8/9] fix numeric precision --- R/pkg_metric_export.R | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/R/pkg_metric_export.R b/R/pkg_metric_export.R index e7e043ad..d890ff4e 100644 --- a/R/pkg_metric_export.R +++ b/R/pkg_metric_export.R @@ -60,17 +60,17 @@ pkg_metric_export.list <- function(x, file = "PACKAGES", ...) { pkg_metric_export.tbl_df <- function(x, file = "PACKAGES", ...) { x <- x[, setdiff(names(x), "pkg_ref")] - records <- apply(x, 1, function(row) { - metrics <- as.list(row) + records <- lapply(seq_len(nrow(x)), function(i) { + row <- x[i, , drop = FALSE] record <- list() - for (name in names(metrics)) { - value <- as.character(metrics[[name]]) + for (name in names(row)) { + value <- as.character(row[[name]]) # Replace NA values with "NA" string - value <- ifelse(is.na(value), "NA", value) + value <- ifelse(is.na(row[[name]]), "NA", value) - # Leave Package and Version untouched, but ensure CamelCase + # Leave Package and Version untouched if (name %in% c("package", "version")) { pascal_name <- paste0(toupper(substring(name, 1, 1)), substring(name, 2)) record[[pascal_name]] <- value @@ -83,7 +83,6 @@ pkg_metric_export.tbl_df <- function(x, file = "PACKAGES", ...) { record }) - # Convert to data frame df <- do.call(rbind.data.frame, lapply(records, as.data.frame, stringsAsFactors = FALSE)) write.dcf(df, file = file) df From e5c6da3b4cd8ae4f9f493cbc5fedc53e8ee83fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Thu, 19 Jun 2025 15:28:27 +0200 Subject: [PATCH 9/9] Update documentation to link to the pkg_metric_import function --- NAMESPACE | 1 + R/pkg_metric_export.R | 2 +- R/pkg_metric_import.R | 15 +++++++++++++++ man/pkg_metric_export.Rd | 4 ++++ man/pkg_metric_import.Rd | 20 ++++++++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 R/pkg_metric_import.R create mode 100644 man/pkg_metric_import.Rd diff --git a/NAMESPACE b/NAMESPACE index 212748f0..652ec811 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -119,6 +119,7 @@ export(metric_score) export(pkg_assess) export(pkg_metric) export(pkg_metric_export) +export(pkg_metric_import) export(pkg_ref) export(pkg_score) export(score_error_NA) diff --git a/R/pkg_metric_export.R b/R/pkg_metric_export.R index d890ff4e..a50b64e9 100644 --- a/R/pkg_metric_export.R +++ b/R/pkg_metric_export.R @@ -21,7 +21,7 @@ to_pascal_case <- function(x) { #' #' @return A character vector, where each element is a DCF-style line #' representing one scored metric (e.g., `"MetricHasNews: 1"`). -#' +#' @seealso pkg_metric_import #' @examples #' \dontrun{ #' # For a single package diff --git a/R/pkg_metric_import.R b/R/pkg_metric_import.R new file mode 100644 index 00000000..cd1ac52b --- /dev/null +++ b/R/pkg_metric_import.R @@ -0,0 +1,15 @@ +#' Import metrics +#' +#' @param file (`character`) Path to the file to import. +#' +#' @returns The object in the same format and class as generated by riskmetric. +#' @export +#' @seealso pkg_metric_export() +pkg_metric_import <- function(file) { + if (!file.exists(file)) { + stop("Please provide a path to a file.") + } + dcf <- read.dcf(file) + dcf <- as.data.frame(dcf) + dcf +} diff --git a/man/pkg_metric_export.Rd b/man/pkg_metric_export.Rd index c283111a..ebcfeb00 100644 --- a/man/pkg_metric_export.Rd +++ b/man/pkg_metric_export.Rd @@ -10,6 +10,7 @@ pkg_metric_export(x, ...) \item{x}{A `tbl_df` or `list` returned by `pkg_score()`, containing scored `pkg_metric` values. The input may come from `pkg_score.tbl_df()` (for many packages) or `pkg_score.list_of_pkg_metric()` (for a single package).} + \item{...}{additional arguments unused} } \value{ @@ -39,3 +40,6 @@ pkg_metric_export(scores[1, ]) # flatten first package's results } } +\seealso{ +pkg_metric_import +} diff --git a/man/pkg_metric_import.Rd b/man/pkg_metric_import.Rd new file mode 100644 index 00000000..1fdbffa5 --- /dev/null +++ b/man/pkg_metric_import.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pkg_metric_import.R +\name{pkg_metric_import} +\alias{pkg_metric_import} +\title{Import metrics} +\usage{ +pkg_metric_import(file) +} +\arguments{ +\item{file}{(`character`) Path to the file to import.} +} +\value{ +The object in the same format and class as generated by riskmetric. +} +\description{ +Import metrics +} +\seealso{ +pkg_metric_export() +}