diff --git a/NAMESPACE b/NAMESPACE index 077018b4..7821681a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,8 +1,11 @@ # Generated by roxygen2: do not edit by hand +S3method(append,datapackage) +S3method(append,default) S3method(print,datapackage) export("resource<-") export(add_resource) +export(append) export(check_package) export(create_package) export(create_schema) diff --git a/R/append.datapackage.R b/R/append.datapackage.R new file mode 100644 index 00000000..ea8e7997 --- /dev/null +++ b/R/append.datapackage.R @@ -0,0 +1,43 @@ +#' Append values to an object +#' +#' An S3 generic version of [base::append()]; see [append.datapackage()]. +#' +#' @param x the vector the values are to be appended to. +#' @param values to be included in the modified vector. +#' @param after a subscript, after which the values are to be appended. +#' +#' @returns A vector containing the values in `x` with the elements of `values` +#' appended after the specified element of `x`. +#' @export +append <- function(x, values, after = length(x)) { + # This function needs to be exported or base::append() will stop working when + # loading the package. Because base append() is not an S3 generic, we need to + # define one to dispatch to append.datapackage() or append.default(). + UseMethod("append") +} + +#' @exportS3Method +append.default <- function(x, values, after = length(x)) { + base::append(x, values, after = after) +} + +#' Append a Data Package +#' +#' Appends values to a Data Package object, preserving its attributes such as +#' directory and class. +#' +#' @param x Data Package object, as returned by [read_package()] or +#' [create_package()]. +#' @inheritParams append +#' @returns A Data Package object with the elements of `values` appended after +#' the specified element of `x`. +#' +#' @exportS3Method +#' +#' @examples +#' p <- example_package() +#' p_app <- append(p, list("$schema" = "just added"), after = 0) +#' p_app +#' attributes(p_app) +append.datapackage <- function(x, values, after = length(x)) { + append_with_attributes(x, values, after = after)} diff --git a/man/append.Rd b/man/append.Rd new file mode 100644 index 00000000..1803b74c --- /dev/null +++ b/man/append.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/append.datapackage.R +\name{append} +\alias{append} +\title{Append values to an object} +\usage{ +append(x, values, after = length(x)) +} +\arguments{ +\item{x}{the vector the values are to be appended to.} + +\item{values}{to be included in the modified vector.} + +\item{after}{a subscript, after which the values are to be appended.} +} +\value{ +A vector containing the values in \code{x} with the elements of \code{values} +appended after the specified element of \code{x}. +} +\description{ +An S3 generic version of \code{\link[base:append]{base::append()}}; see \code{\link[=append.datapackage]{append.datapackage()}}. +} diff --git a/man/append.datapackage.Rd b/man/append.datapackage.Rd new file mode 100644 index 00000000..424236b5 --- /dev/null +++ b/man/append.datapackage.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/append.datapackage.R +\name{append.datapackage} +\alias{append.datapackage} +\title{Append a Data Package} +\usage{ +\method{append}{datapackage}(x, values, after = length(x)) +} +\arguments{ +\item{x}{Data Package object, as returned by \code{\link[=read_package]{read_package()}} or +\code{\link[=create_package]{create_package()}}.} + +\item{values}{to be included in the modified vector.} + +\item{after}{a subscript, after which the values are to be appended.} +} +\value{ +A Data Package object with the elements of \code{values} appended after +the specified element of \code{x}. +} +\description{ +Appends values to a Data Package object, preserving its attributes such as +directory and class. +} +\examples{ +p <- example_package() +p_app <- append(p, list("$schema" = "just added"), after = 0) +p_app +attributes(p_app) +}