diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml deleted file mode 100644 index 71f97a7a..00000000 --- a/.github/workflows/R-CMD-check.yaml +++ /dev/null @@ -1,64 +0,0 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples -# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help -on: - push: - branches: [main, master] - pull_request: - branches: [main, master] - -name: R-CMD-check - -jobs: - R-CMD-check: - runs-on: ${{ matrix.config.os }} - - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - - strategy: - fail-fast: false - matrix: - config: - - {os: macOS-latest, r: 'release'} - - {os: windows-latest, r: 'release'} - - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - - {os: ubuntu-latest, r: 'release'} - - {os: ubuntu-latest, r: 'oldrel/1'} - - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - R_KEEP_PKG_SOURCE: yes - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-pandoc@v1 - - - uses: r-lib/actions/setup-r@v1 - with: - r-version: ${{ matrix.config.r }} - http-user-agent: ${{ matrix.config.http-user-agent }} - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v1 - with: - extra-packages: rcmdcheck - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_: false - run: | - options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} - - - name: Show testthat output - if: always() - run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash - - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main - with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check diff --git a/.github/workflows/check-standard.yaml b/.github/workflows/check-standard.yaml new file mode 100644 index 00000000..2c39720f --- /dev/null +++ b/.github/workflows/check-standard.yaml @@ -0,0 +1,49 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true \ No newline at end of file diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 3c0da1c9..0ceda36a 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -1,4 +1,4 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: @@ -15,16 +15,36 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: covr + extra-packages: any::covr + needs: coverage - name: Test coverage - run: covr::codecov() + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + ) shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package \ No newline at end of file diff --git a/.gitignore b/.gitignore index be00e4d6..0ebefc35 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ tags /doc/ /Meta/ + +vignettes/manage-data-columns_cache diff --git a/Container.Rd b/Container.Rd deleted file mode 100644 index a5a6fb06..00000000 --- a/Container.Rd +++ /dev/null @@ -1,688 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-ContainerR6.R -\docType{class} -\name{Container} -\alias{Container} -\title{Container Class} -\description{ -This class implements a container data structure with typical -member functions to insert, delete and access elements from the container. -For the standard S3 interface, see \code{\link[=container]{container()}}. -} -\details{ -This class inherits from class \link{Iterable} and serves as the base -class for \link{Deque}, \link{Set}, and \link{Dict}. -} -\examples{ -co = Container$new(1:5, c = Container$new("a", 1), l = list()) -co$print() -co$length() -co$names() -co$clear() - -# Extract -co = Container$new(a = 1, b = 2, c = 3, d = 4) -co$at(1:2) -co$at(c(1, 4)) -co$at(list("d", 2)) -co$at2(1) - -try(co$at(0:2)) # index must be > 0 - -co$peek_at(0:2) -co$peek_at(0:2, default = 1) - -# Replace -co$replace(4, 9) -co$replace(9, 11) -co$replace_at(1, -1) - -try(co$replace_at(11, 1)) # index 11 exceeds length of Container - -# Delete -co$delete(-1) -co$delete_at(3) - -try(co$delete_at(3)) # index 3 exceeds length of Container - -co$discard(3) - -co2 = Container$new(b = 0) -co2$add(0, name = "a") -co$update(co2) -co$pop(1) -co -} -\seealso{ -\code{\link[=container]{container()}}, \link{Iterable}, \link{Deque}, \link{Set}, and \link{Dict} -} -\author{ -Roman Pahl -} -\section{Super class}{ -\code{\link[container:Iterable]{container::Iterable}} -> \code{Container} -} -\section{Methods}{ -\subsection{Public methods}{ -\itemize{ -\item \href{#method-Container-new}{\code{Container$new()}} -\item \href{#method-Container-add}{\code{Container$add()}} -\item \href{#method-Container-at}{\code{Container$at()}} -\item \href{#method-Container-at2}{\code{Container$at2()}} -\item \href{#method-Container-clear}{\code{Container$clear()}} -\item \href{#method-Container-count}{\code{Container$count()}} -\item \href{#method-Container-delete}{\code{Container$delete()}} -\item \href{#method-Container-delete_at}{\code{Container$delete_at()}} -\item \href{#method-Container-discard}{\code{Container$discard()}} -\item \href{#method-Container-discard_at}{\code{Container$discard_at()}} -\item \href{#method-Container-empty}{\code{Container$empty()}} -\item \href{#method-Container-get_compare_fun}{\code{Container$get_compare_fun()}} -\item \href{#method-Container-has}{\code{Container$has()}} -\item \href{#method-Container-has_name}{\code{Container$has_name()}} -\item \href{#method-Container-is_empty}{\code{Container$is_empty()}} -\item \href{#method-Container-length}{\code{Container$length()}} -\item \href{#method-Container-names}{\code{Container$names()}} -\item \href{#method-Container-peek_at}{\code{Container$peek_at()}} -\item \href{#method-Container-peek_at2}{\code{Container$peek_at2()}} -\item \href{#method-Container-pop}{\code{Container$pop()}} -\item \href{#method-Container-print}{\code{Container$print()}} -\item \href{#method-Container-rename}{\code{Container$rename()}} -\item \href{#method-Container-replace}{\code{Container$replace()}} -\item \href{#method-Container-replace_at}{\code{Container$replace_at()}} -\item \href{#method-Container-remove}{\code{Container$remove()}} -\item \href{#method-Container-size}{\code{Container$size()}} -\item \href{#method-Container-type}{\code{Container$type()}} -\item \href{#method-Container-update}{\code{Container$update()}} -\item \href{#method-Container-values}{\code{Container$values()}} -\item \href{#method-Container-clone}{\code{Container$clone()}} -} -} -\if{html}{\out{ -
Inherited methods - -
-}} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-new}{}}} -\subsection{Method \code{new()}}{ -constructor -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$new(...)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{...}}{initial elements put into the \code{Container}} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-add}{}}} -\subsection{Method \code{add()}}{ -add element -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$add(value, name = NULL)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{value}}{value of \code{ANY} type to be added to the \code{Container}.} - -\item{\code{name}}{\code{character} optional name attribute of the value.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-at}{}}} -\subsection{Method \code{at()}}{ -Same as \code{at2} (see below) but accepts a vector of -indices and always returns a \code{Container} object. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$at(index)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{index}}{vector of indices.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{Container} object with the extracted elements. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-at2}{}}} -\subsection{Method \code{at2()}}{ -Extract value at index. If index is invalid or not -found, an error is signaled. If given as a string, the element -matching the name is returned. If there are two or more identical -names, the value of the first match (i.e. \emph{leftmost} element) is -returned. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$at2(index)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{index}}{Must be a single number > 0 or a string.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -If given as a number, the element at the corresponding -position, and if given as a string, the element at the -corresponding name matching the given string is returned. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-clear}{}}} -\subsection{Method \code{clear()}}{ -delete all elements from the \code{Container} -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$clear()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -the cleared \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-count}{}}} -\subsection{Method \code{count()}}{ -Count number of element occurences. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$count(elem)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{elem}}{element to be counted.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{integer} number of \code{elem} occurences in the \code{\link[=Container]{Container()}} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-delete}{}}} -\subsection{Method \code{delete()}}{ -Search for occurence(s) of \code{elem} in \code{Container} and -remove first one that is found. If \code{elem} does not exist, an error -is signaled. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$delete(elem)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{elem}}{element to be removed from the \code{Container}.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-delete_at}{}}} -\subsection{Method \code{delete_at()}}{ -Delete value at given index. If index is not found, an -error is signaled. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$delete_at(index)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{index}}{\code{character} or \code{numeric} index} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-discard}{}}} -\subsection{Method \code{discard()}}{ -Search for occurence(s) of \code{elem} in \code{Container} and -remove first one that is found. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$discard(elem)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{elem}}{element to be discarded from the \code{Container}. If not -found, the operation is ignored and the object is \emph{not} altered.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-discard_at}{}}} -\subsection{Method \code{discard_at()}}{ -Discard value at given index. If index is not found, -the operation is ignored. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$discard_at(index)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{index}}{\code{character} or \code{numeric} index} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-empty}{}}} -\subsection{Method \code{empty()}}{ -This function is deprecated. Use \code{\link[=is_empty]{is_empty()}} instead. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$empty()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-get_compare_fun}{}}} -\subsection{Method \code{get_compare_fun()}}{ -Get comparison function used internally by the -\code{Container} object to compare elements. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$get_compare_fun()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-has}{}}} -\subsection{Method \code{has()}}{ -Determine if \code{Container} has some element. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$has(elem)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{elem}}{element to search for} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{TRUE} if \code{Container} contains \code{elem} else \code{FALSE} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-has_name}{}}} -\subsection{Method \code{has_name()}}{ -Determine if \code{Container} object contains an element -with the given name. If called with no argument, the function -determines whether \emph{any} element is named. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$has_name(name)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{name}}{\code{character} the name} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{TRUE} if \code{Container} has the \code{name} otherwise \code{FALSE} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-is_empty}{}}} -\subsection{Method \code{is_empty()}}{ -Check if \code{Container} is empty -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$is_empty()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -\code{TRUE} if the \code{Container} is empty else \code{FALSE}. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-length}{}}} -\subsection{Method \code{length()}}{ -Number of elements of the \code{Container}. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$length()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -\code{integer} length of the \code{Container}, that is, the number of -elements it contains. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-names}{}}} -\subsection{Method \code{names()}}{ -Names of the elements. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$names()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -\code{character} the names of the elements contained in \code{x} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-peek_at}{}}} -\subsection{Method \code{peek_at()}}{ -Same as \code{peek_at2} (see below) but accepts a vector of -indices and always returns a \code{Container} object. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$peek_at(index, default = NULL)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{index}}{vector of indices.} - -\item{\code{default}}{the default value to return in case the value at -\code{index} is not found.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{Container} object with the extracted elements. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-peek_at2}{}}} -\subsection{Method \code{peek_at2()}}{ -Peek at index and extract value. If index is invalid, -missing, or not not found, return \code{default} value. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$peek_at2(index, default = NULL)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{index}}{\code{numeric} or \code{character} index to be accessed.} - -\item{\code{default}}{the default value to return in case the value at -\code{index} is not found.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the value at the given index or (if not found) the given -default value. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-pop}{}}} -\subsection{Method \code{pop()}}{ -Get value at index and remove it from \code{Container}. -If \code{index} is not found, raise an error. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$pop(index)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{index}}{Must be a single number > 0 or a string.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -If given as a number, the element at the corresponding -position, and if given as a string, the element at the -corresponding name matching the given string is returned. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-print}{}}} -\subsection{Method \code{print()}}{ -Print object representation -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$print(...)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{...}}{further arguments passed to \code{\link[=format]{format()}}} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -invisibly returns the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-rename}{}}} -\subsection{Method \code{rename()}}{ -Rename a \code{key} in the \code{Container}. An error is signaled, -if either the \code{old} key is not in the \code{Container} or the \code{new} key results -in a name-clash with an existing key. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$rename(old, new)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{old}}{\code{character} name of key to be renamed.} - -\item{\code{new}}{\code{character} new key name.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-replace}{}}} -\subsection{Method \code{replace()}}{ -Replace one element by another element. -Search for occurence of \code{old} and, if found, replace it by \code{new}. -If \code{old} does not exist, an error is signaled, unless \code{add} was -set to \code{TRUE}, in which case \code{new} is added. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$replace(old, new, add = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{old}}{element to be replaced} - -\item{\code{new}}{element to be put instead of old} - -\item{\code{add}}{\code{logical} if \code{TRUE} the \code{new} element is added in case -\code{old} does not exists.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-replace_at}{}}} -\subsection{Method \code{replace_at()}}{ -Replace value at given index. -Replace value at index by given value. If index is not found, an -error is signalled, unless \code{add} was set to \code{TRUE}, in which case -\code{new} is added. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$replace_at(index, value, add = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{index}}{\code{character} or \code{numeric} index} - -\item{\code{value}}{\code{ANY} new value to replace the old one.} - -\item{\code{add}}{\code{logical} if \code{TRUE} the new \code{value} element would be added -in case \code{index} did not exists.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-remove}{}}} -\subsection{Method \code{remove()}}{ -This function is deprecated. Use \code{\link[=delete]{delete()}} instead. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$remove(elem)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{elem}}{element to be deleted from the \code{Container}. If element -is not found in the \code{Container}, an error is signaled.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Container} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-size}{}}} -\subsection{Method \code{size()}}{ -This function is deprecated. Use \code{\link[=length]{length()}} instead. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$size()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -the \code{Container} length -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-type}{}}} -\subsection{Method \code{type()}}{ -This function is deprecated and of no real use anymore. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$type()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -type (or mode) of internal vector containing the elements -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-update}{}}} -\subsection{Method \code{update()}}{ -Add elements of \code{other} to this if the name is -not in the \code{Container} and update elements with existing names. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$update(other)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{other}}{\code{Iterable} object used to update this.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -returns the \code{Container} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-values}{}}} -\subsection{Method \code{values()}}{ -Get \code{Container} values -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$values()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -elements of the container as a base list -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Container-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Container$clone(deep = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} -} diff --git a/ContainerS3.Rd b/ContainerS3.Rd deleted file mode 100644 index 9362e9be..00000000 --- a/ContainerS3.Rd +++ /dev/null @@ -1,418 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-ContainerS3.R, R/GroupGenericMath.R, -% R/GroupGenericSummary.R, R/Ops-arithmetic.R, R/Ops-compare.R, -% R/Ops-extract.R, R/Ops-replace.R, R/add.R, R/at.R, R/at2.R, R/clear.R, -% R/clone.R, R/count.R, R/delete.R, R/delete_at.R, R/discard.R, -% R/discard_at.R, R/has.R, R/has_name.R, R/is_empty.R, R/peek_at.R, -% R/peek_at2.R, R/pop.R, R/rename.R, R/replace.R, R/replace_at.R -\name{ContainerS3} -\alias{ContainerS3} -\alias{container} -\alias{cont} -\alias{as.container} -\alias{as.cont} -\alias{is.container} -\alias{as.list.Container} -\alias{length.Container} -\alias{names.Container} -\alias{names<-.Container} -\title{Container - Enhancing R's list} -\usage{ -container(...) - -cont(...) - -as.container(x) - -as.cont(x) - -is.container(x) - -\method{as.list}{Container}(x, ...) - -\method{length}{Container}(x) - -\method{names}{Container}(x) - -\method{names}{Container}(x) <- value -} -\arguments{ -\item{...}{(possibly named) elements to be put into or removed from the -\link{Container}, or additional arguments passed from and to methods.} - -\item{x}{\code{R} object of \code{ANY} type for \link{as.container} and \link{is.container} -or of class \link{Container} for the \code{S3} methods.} - -\item{value}{\code{character} vector of names.} -} -\description{ -A container is a data structure with typical member -functions to insert, delete and access elements from the container -object. It can be considered as a base R \link{list} with -extended functionality. The \link{Container} class also serves as the base -class for \link{Deque}, \link{Set}, and \link{Dict} objects. -} -\details{ -Methods that alter \link{Container} objects usually come in two versions -providing either copy or reference semantics where the latter start with -\code{'ref_'} to note the reference semantic, for example, \code{\link[=add]{add()}} and \code{\link[=ref_add]{ref_add()}}. - -\itemize{ -\item \code{container(...)} initializes and returns a \link{Container} object. -} - -\itemize{ -\item \code{cont(...)} is a short cut for \code{container(...)}. -} - -\itemize{ -\item \code{as.container(x)} or \code{as.cont(x)} coerce \code{x} to a \link{Container} -} - -\itemize{ -\item \code{is.container(x)} check if \code{x} is a \link{Container} -} - -\itemize{ -\item \code{as.list(x)} converts container \code{x} to a base R \link{list}. All of -the container's elements are copied (deeply) during the conversion. -} - -\itemize{ -\item \code{length(x)} return the number of elements contained in \code{x}. -} - -\itemize{ -\item \code{names(x)} return the names of the elements contained in \code{x}. -} - -\itemize{ -\item \code{names(x) <- value} sets the names of \code{x}. -} - -\itemize{ -\item \code{x + y} combines \code{x} and \code{y} into a new container by appending \code{y} -to \code{x}. -} - -\itemize{ -\item \code{x - y} element-wise discards all items of \code{y} from \code{x}, given -the element was contained in \code{x}. The result is always a container. -} - -\itemize{ -\item \code{x == y} is \code{TRUE} if the contents of \code{x} and \code{y} are -lexicographically \emph{equal}. -} - -\itemize{ -\item \code{x != y} is \code{TRUE} if the contents of \code{x} and \code{y} are -not equal. -} - -\itemize{ -\item \code{x < y} is \code{TRUE} if the contents of x are lexicographically -\emph{less} than the contents of y. -} - -\itemize{ -\item \code{x <= y} is \code{TRUE} if the contents of x are lexicographically -\emph{less} than or \emph{equal} to the contents of y. -} - -\itemize{ -\item \code{add(.x, ...)} and \code{ref_add(.x, ...)} add elements to \code{.x}. -} - -\itemize{ -\item \code{at(.x, ...,)} returns the value at the given indices. Indices -can be letters or numbers or both. All indices must exist. -} - -\itemize{ -\item \code{at2(x, index)} returns the value at the given index or signals an error -if not found. -} - -\itemize{ -\item \code{clear(x)} and \code{ref_clear(x)} remove all elements from \code{x}. -} - -\itemize{ -\item \code{clone(x)} create a copy of \code{x}. -} - -\itemize{ -\item \code{count(x, elem)} count how often \code{elem} occurs in \code{x}. -} - -\itemize{ -\item \code{delete(.x, ...)} and \code{ref_delete(.x, ...)} find and remove elements. -If one or more elements don't exist, an error is signaled. -} - -\itemize{ -\item \code{delete_at(.x, ...)} and \code{ref_delete_at(.x, ...)} find and remove values at -given indices. If any given index is invalid, an error is signaled. -} - -\itemize{ -\item \code{discard(.x, ...)} and \code{ref_discard(.x, ...)} find and discard elements. -Elements that don't exist, are ignored. -} - -\itemize{ -\item \code{discard_at(.x, ...)} and \code{ref_discard_at(.x, ...)} find and discard values -at given indices. Invalid indices are ignored. -} - -\itemize{ -\item \code{has(x, elem)} \code{TRUE} if element is in \code{x} and otherwise \code{FALSE}. -} - -\itemize{ -\item \code{has_name(x, name)} check if \code{name} is in \code{x} -} - -\itemize{ -\item \code{is_empty(x)} \code{TRUE} if object is empty otherwise \code{FALSE} -} - -\itemize{ -\item \code{peek_at(x, ..., .default = NULL)} returns the value at the given indices -or (if not found) the given default value. -} - -\itemize{ -\item \code{peek_at2(x, index, default)} returns the value at the given index or (if -not found) the given default value. -} - -\itemize{ -\item \code{ref_pop(.x, index)} return element at given index and remove it -from the \code{container} object. -} - -\itemize{ -\item \code{rename(.x, old, new)} and \code{ref_rename(.x, old, new)} rename one or more keys -from \code{old} to \code{new}, respectively, by copy and in place (i.e. by reference). -} - -\itemize{ -\item \code{replace(.x, old, new, add = FALSE)} and -\code{ref_replace(.x, old, new, add = FALSE)} try to find element \code{old} and -replace it with element \code{new}. If \code{old} does not exist, an error is raised, -unless \code{add} was set to \code{TRUE}. -} - -\itemize{ -\item \code{replace_at(.x, .., .add = FALSE)} and \code{ref_replace_at(.x, ..., .add = FALSE)} -replace values at given indices. If a given index is invalid, an error is -signaled unless \code{.add} was set to \code{TRUE}. -} -} -\examples{ -co = container(1:5, c = container("a", 1), l = list()) -is.container(co) -print(co) -length(co) -names(co) - -unpack(co) # flatten recursively similar to unlist - -# Math -co = container(1, 2, -(3:5)) -co -abs(co) -cumsum(co) -round(co) -exp(co) - -# Summary -range(co) -min(co) -max(co) - -# Arithmetic -c1 = container(1, 1:2) -c2 = container(2, 1:2) -c1 + c2 # same as c(c1, c2) -c2 + c1 # same as c(c2, c1) - -c1 - c2 -c2 - c1 -c1 - c1 - -# Comparison -c1 = container(1, 2, 3) -c2 = container(1, 3, 2) -c1 == c1 # TRUE -c1 != c2 # TRUE -c1 <= c1 # TRUE -c1 == c2 # FALSE -c1 < c2 # TRUE -c1 < container(2) # TRUE -c1 < container() # FALSE - -# Extract or replace -co = container(a = 1, b = 2, c = 3, d = 4) -co[1:2] -co[1, 4] -co["d", 2] -co[list("d", 2)] -co[0:10] - -co = container(a = 1, b = 2) -co[[1]] -co[["a"]] -co[["x"]] -co = container(a = 1, b = "bar") -(co[1:2] <- 1:2) - -try({ -co[3] <- 3 # index out of range -}) -(co[list(1, "b")] <- 3:4) # mixed numeric/character index - -co = container(a = 1, b = 2) -co[[1]] <- 9 -co[["b"]] <- 8 -co[["x"]] <- 7 -co$z <- 99 -print(co) - -# Replace 8 by 0 -co[[{8}]] <- 0 -print(co) - - -co = container(a = 1, b = "bar") -co$f <- 3 -co$b <- 2 -co - - -co = container(1) -add(co, 1, b = 2, c = container(1:3)) - - -co = container(a = 1, 2, b = 3, 4) -at(co, 1:3) -at(co, "a", "b", 2) -try(at(co, "x")) # index 'x' not found -try(at(co, 1:10)) # index 5 exceeds length of Container - -co = container(a = 1, 2, b = 3, 4) -at2(co, 1) -at2(co, "a") -at2(co, 2) -try(at2(co, "x")) # index 'x' not found -try(at2(co, 5)) # index 5 exceeds length of Container - -co = container(1, 2, mean) -clear(co) -print(co) # Original was not touched -ref_clear(co) # Clears original -print(co) - -co = container(1, 2, 3) -co2 = clone(co) -co == co2 - -co = container("a", "b", "a", mean, mean) -count(co, "a") -count(co, mean) -count(co, "c") - -co = container("a", 1:3, iris) -print(co) -delete(co, 1:3, "a") -delete(co, iris) -try({ -delete(co, "b") # "b" is not in Container -}) - -co = container(a = 1, b = 2, 3) -delete_at(co, "a", "b") # [3] -delete_at(co, 1:2) # [3] -delete_at(co, "a", 3) # [b = 2] -try({ - delete_at(co, 4) # index out of range - delete_at(co, "x") # names(s) not found: 'x' -}) - -co = container("a", num = 1:3, data = iris) -print(co) -discard(co, 1:3, "a") -discard(co, iris) -discard(co, "b") # ignored - -co = container(a = 1, b = 2, 3) -discard_at(co, "a", "b") # [3] -discard_at(co, 1:2) # [3] -discard_at(co, "a", 3) # [b = 2] -discard_at(co, "x") # ignored - -co = container(1, 2, mean) -has(co, 1) # TRUE -has(co, mean) # TRUE -has(co, 1:2) # FALSE - -co = container(a = 1, 2, f = mean) -has_name(co, "a") # TRUE -has_name(co, "f") # TRUE -has_name(co, "2") # FALSE - -co = container(1, 2) -is_empty(co) -is_empty(clear(co)) - -co = container(a = 1, 2, b = 3, 4) -peek_at(co, 1) -peek_at(co, "a") -peek_at(co, "x") -peek_at(co, "x", .default = 0) -peek_at(co, "a", "x", 2, 9, .default = -1) - -co = container(a = 1, 2, b = 3, 4) -peek_at2(co, 1) -peek_at2(co, "a") -peek_at2(co, "x") -peek_at2(co, "x", default = 0) - -co = container(a = 1, b = 1:3, d = "foo") -ref_pop(co, "b") -ref_pop(co, 1) - -try({ -ref_pop(co, "x") # index 'x' not found -}) -co = container(a = 1, b = 2, 3) -rename(co, c("a", "b"), c("a1", "y")) -print(co) -ref_rename(co, c("a", "b"), c("a1", "y")) -print(co) - -co = container("x", 9) -replace(co, 9, 0) -replace(co, "x", 0) -try({ -replace(co, "z", 0) # old element ("z") is not in Container -}) -replace(co, "z", 0, add = TRUE) # ok, adds the element - -co = container(a = 0, b = "z") -replace_at(co, a = 1, b = 2) -replace_at(co, 1:2, 1:2) # same -replace_at(co, c("a", "b"), list(1, 2)) # same - -try({ -replace_at(co, x = 1) # names(s) not found: 'x' -}) -replace_at(co, x = 1, .add = TRUE) # ok (adds x = 1) -} -\seealso{ -For the class documentation see \link{Container}. -Objects of the derived classes can be created by \link{deque}, \link{setnew}, and -\link{dict}. -} diff --git a/DESCRIPTION b/DESCRIPTION index 10c60187..1d09f606 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: container Type: Package Title: Extending Base 'R' Lists -Version: 1.0.3 -Date: 2022-11-14 +Version: 1.0.4 +Date: 2022-12-11 Authors@R: person("Roman", "Pahl", email = "roman.pahl@gmail.com", role = c("aut", "cre")) diff --git a/Deque.Rd b/Deque.Rd deleted file mode 100644 index 3cab66cf..00000000 --- a/Deque.Rd +++ /dev/null @@ -1,209 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-DequeR6.R -\name{Deque} -\alias{Deque} -\title{Deque Class} -\description{ -Deques are a generalization of stacks and queues typically -with methods to add, delete and access elements at both sides of the -underlying data sequence. As such, the \link{Deque} can also be used to mimic -both stacks and queues. For the standard S3 interface, see \code{\link[=deque]{deque()}}. -} -\details{ -This class inherits from class \code{\link[=Container]{Container()}} and extends it by -\code{popleft} and \code{peek} methods, and reverse and rotate functionality. -} -\examples{ -d = Deque$new(1, 2, s = "a", v = 1:3) -d$addleft(0) -d$peekleft() -d$peek() - -d$popleft() -d$rev() - -d$rotate() -d$rotate(2) -d$rotate(-3) -} -\seealso{ -\code{\link[=Container]{Container()}}, \code{\link[=deque]{deque()}} -} -\section{Super classes}{ -\code{\link[container:Iterable]{container::Iterable}} -> \code{\link[container:Container]{container::Container}} -> \code{Deque} -} -\section{Methods}{ -\subsection{Public methods}{ -\itemize{ -\item \href{#method-Deque-addleft}{\code{Deque$addleft()}} -\item \href{#method-Deque-peek}{\code{Deque$peek()}} -\item \href{#method-Deque-peekleft}{\code{Deque$peekleft()}} -\item \href{#method-Deque-popleft}{\code{Deque$popleft()}} -\item \href{#method-Deque-rev}{\code{Deque$rev()}} -\item \href{#method-Deque-rotate}{\code{Deque$rotate()}} -\item \href{#method-Deque-clone}{\code{Deque$clone()}} -} -} -\if{html}{\out{ -
Inherited methods - -
-}} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Deque-addleft}{}}} -\subsection{Method \code{addleft()}}{ -Add element to left side of the \code{Deque}. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Deque$addleft(value, name = NULL)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{value}}{value of \code{ANY} type to be added to the \code{Deque}.} - -\item{\code{name}}{\code{character} optional name attribute of the value.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Deque} object. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Deque-peek}{}}} -\subsection{Method \code{peek()}}{ -Peek at last element of the \code{Deque}. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Deque$peek(default = NULL)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{default}}{returned default value if \code{Deque} is empty.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -element 'peeked' on the right -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Deque-peekleft}{}}} -\subsection{Method \code{peekleft()}}{ -Peek at first element of the \code{Deque}. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Deque$peekleft(default = NULL)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{default}}{returned default value if \code{Deque} is empty.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -element 'peeked' on the left -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Deque-popleft}{}}} -\subsection{Method \code{popleft()}}{ -Delete and return element from the left side of the \code{\link[=Deque]{Deque()}}. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Deque$popleft()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -element 'popped' from the left side of the \code{\link[=Deque]{Deque()}} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Deque-rev}{}}} -\subsection{Method \code{rev()}}{ -Reverse all elements of the \code{\link[=Deque]{Deque()}} in-place. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Deque$rev()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -the \code{Deque()} object. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Deque-rotate}{}}} -\subsection{Method \code{rotate()}}{ -Rotate all elements \code{n} steps to the right. If n is -negative, rotate to the left. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Deque$rotate(n = 1L)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{n}}{\code{integer} number of steps to rotate} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -returns the \code{Deque()} object. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Deque-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Deque$clone(deep = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} -} diff --git a/DequeS3.Rd b/DequeS3.Rd deleted file mode 100644 index 1ef3a575..00000000 --- a/DequeS3.Rd +++ /dev/null @@ -1,159 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-DequeS3.R, R/GroupGenericMath.R, -% R/GroupGenericSummary.R, R/Ops-arithmetic.R, R/addleft.R, R/peek.R, R/pop.R, -% R/rev.R, R/rotate.R -\name{DequeS3} -\alias{DequeS3} -\alias{deque} -\alias{as.deque} -\alias{is.deque} -\title{Deque - Double-Ended Queue} -\usage{ -deque(...) - -as.deque(x) - -is.deque(x) -} -\arguments{ -\item{...}{initial elements put into the \code{Deque}.} - -\item{x}{\code{R} object of \code{ANY} type for \code{\link[=as.deque]{as.deque()}} and \code{\link[=is.deque]{is.deque()}} -or of class \code{Deque} for the \code{S3} methods.} -} -\description{ -Deques are a generalization of stacks and queues typically -with methods to add, remove and access elements at both sides of the -underlying data sequence. As such, the \link{deque} can also be used to mimic -both stacks and queues. -} -\details{ -Methods that alter \link{Deque} objects usually come in two versions -providing either copy or reference semantics where the latter start with -\code{'ref_'} to note the reference semantic, for example, \code{add()} and \code{ref_add()}. - -\itemize{ -\item \code{deque(...)} initializes and returns an object of class \code{Deque} -} - -\itemize{ -\item \code{as.deque(x)} coerces \code{x} to a deque. -} - -\itemize{ -\item \code{is.deque(x)} returns \code{TRUE} if \code{x} is of class \code{Deque} -and \code{FALSE} otherwise. -} - -\itemize{ -\item \code{x + y} combines \code{x} and \code{y} into a new deque by appending \code{y} -to \code{x}. -} - -\itemize{ -\item \code{x - y} element-wise removes all items of \code{y} from \code{x}, given -the element was contained in \code{x}. -} - -\itemize{ -\item \code{addleft(.x, ...)} adds (possibly named) elements to left side of \code{.x}. -\item \code{ref_addleft(.x, ...)} same as \code{addleft(.x, ...)} but adds by reference. -} - -\itemize{ -\item \code{peek(x, default = NULL)} peek at last element. If \code{x} is empty, return -\code{default}. -\item \code{peekleft(x, default = NULL)} peek at first element. If \code{x} is empty, -return \code{default}. -} - -\itemize{ -\item \code{ref_pop(.x)} pop last element. If \code{.x} is empty, an error is given. -\item \code{ref_popleft(.x)} pop first element. If \code{.x} is empty, an error is given. -} - -\itemize{ -\item \code{rev(x)} and \code{ref_rev(x)} reverses all elements being done on a copy or in -place, respectively. -} - -\itemize{ -\item \code{rotate(x, n)} rotate all elements \code{n} steps to the right, If \code{n} is -negative, rotate to the left. -} -} -\examples{ -d = deque(1, 2, s = "a", v = 1:3) -is.deque(d) -print(d) -length(d) -names(d) -as.list(d) -rev(d) - -l = list(0, 1) -d2 = as.deque(l) -d + d2 -c(d, d2) # same as d + d2 -d2 + d -d - d2 -c(d2, d) # same as d2 + d -d2 - d -# Math -d = deque(1, 2, -(3:5)) -d -abs(d) -cumsum(d) -round(d) -exp(d) - -# Summary -range(d) -min(d) -max(d) - -d1 = deque(1, 1:2) -d2 = deque(2, 1:2) -d1 + d2 # same as c(d1, d2) -d2 + d1 # same as c(d2, d1) - -d1 - d2 -d2 - d1 -d1 - d1 - - -d = deque(0) -add(d, a = 1, b = 2) # |0, a = 1, b = 2| -addleft(d, a = 1, b = 2) # |b = 2, a = 1, 0| - -d = deque(1, 2, 3) -peek(d) -peekleft(d) -peek(deque()) -peek(deque(), default = 0) -peekleft(deque(), default = 0) -d = deque(1, 2, 3) -ref_pop(d) -print(d) -ref_popleft(d) -print(d) - -try({ -ref_pop(deque()) # pop at empty Deque -}) - -d = deque(a = 1, b = 2, 3) -rev(d) -print(d) -ref_rev(d) -print(d) - -d = deque(1, 2, 3, 4) -rotate(d) -rotate(d, n = 2) - -} -\seealso{ -See \code{\link[=container]{container()}} for all inherited methods. For the full class -documentation see \code{\link[=Deque]{Deque()}} and it's superclass \link[=container]{Container()}. -} diff --git a/Dict.Rd b/Dict.Rd deleted file mode 100644 index e936f06a..00000000 --- a/Dict.Rd +++ /dev/null @@ -1,319 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-DictR6.R -\name{Dict} -\alias{Dict} -\title{Dict Class} -\description{ -The \code{\link[=Dict]{Dict()}} resembles Python's dict type, and is implemented -as a specialized associative \code{\link[=Container]{Container()}}. -For the standard S3 interface, see \link[=Dict]{dict()}. -} -\details{ -This class inherits from class \code{\link[=Container]{Container()}} and overwrides some -methods to account for the associative key-value pair semantic. -Internally, all key-value pairs are stored in a hash-table and the -elements are always sorted lexicographically by their keys. -} -\examples{ -d = Dict$new(o = "one", na = NA, a = 1) -d -d$keys() - -d$add("li", list(1, 2)) -d$discard_at("na") -d$replace(1, 9) - -d2 = Dict$new(a = 0, b = 1) -d$update(d2) -} -\seealso{ -\code{\link[=Container]{Container()}}, \code{\link[=dict]{dict()}} -} -\section{Super classes}{ -\code{\link[container:Iterable]{container::Iterable}} -> \code{\link[container:Container]{container::Container}} -> \code{Dict} -} -\section{Methods}{ -\subsection{Public methods}{ -\itemize{ -\item \href{#method-Dict-new}{\code{Dict$new()}} -\item \href{#method-Dict-add}{\code{Dict$add()}} -\item \href{#method-Dict-discard_at}{\code{Dict$discard_at()}} -\item \href{#method-Dict-get}{\code{Dict$get()}} -\item \href{#method-Dict-keys}{\code{Dict$keys()}} -\item \href{#method-Dict-remove}{\code{Dict$remove()}} -\item \href{#method-Dict-replace}{\code{Dict$replace()}} -\item \href{#method-Dict-set}{\code{Dict$set()}} -\item \href{#method-Dict-sort}{\code{Dict$sort()}} -\item \href{#method-Dict-update}{\code{Dict$update()}} -\item \href{#method-Dict-values}{\code{Dict$values()}} -\item \href{#method-Dict-clone}{\code{Dict$clone()}} -} -} -\if{html}{\out{ -
Inherited methods - -
-}} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-new}{}}} -\subsection{Method \code{new()}}{ -\code{Dict} constructor -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$new(...)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{...}}{initial elements put into the \code{Dict}} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -returns the \code{Dict} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-add}{}}} -\subsection{Method \code{add()}}{ -If \code{name} not yet in \code{Dict}, insert \code{value} at \code{name}, -otherwise signal an error. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$add(name, value)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{name}}{\code{character} variable name under which to store \code{value}.} - -\item{\code{value}}{the value to be added to the \code{Dict}.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Dict} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-discard_at}{}}} -\subsection{Method \code{discard_at()}}{ -Discard value at given index. If index is not found, -the operation is ignored. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$discard_at(index)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{index}}{\code{character} or \code{numeric} index} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Dict} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-get}{}}} -\subsection{Method \code{get()}}{ -This function is deprecated. Use \code{\link[=at2]{at2()}} instead. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$get(key)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{key}}{\code{character} name of key.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -If \code{key} in \code{Dict}, return value at \code{key}, else throw error. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-keys}{}}} -\subsection{Method \code{keys()}}{ -Get all keys. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$keys()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -\code{character} vector of all keys. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-remove}{}}} -\subsection{Method \code{remove()}}{ -This function is deprecated. Use \code{\link[=delete]{delete()}} instead. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$remove(key)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{key}}{\code{character} name of key.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -If \code{key} in \code{Dict}, remove it, otherwise raise an error. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-replace}{}}} -\subsection{Method \code{replace()}}{ -Replace one element by another element. -Search for occurence of \code{old} and, if found, replace it by \code{new}. -If \code{old} does not exist, an error is signaled. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$replace(old, new)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{old}}{element to be replaced} - -\item{\code{new}}{element to be put instead of old} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Dict} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-set}{}}} -\subsection{Method \code{set()}}{ -This function is deprecated. Use \code{\link[=replace]{replace()}} instead. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$set(key, value, add = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{key}}{\code{character} name of key.} - -\item{\code{value}}{the value to be set} - -\item{\code{add}}{\code{logical} if \code{TRUE} the value is set regardless whether -\code{key} already exists in \code{Dict}.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -returns the \code{Dict} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-sort}{}}} -\subsection{Method \code{sort()}}{ -Sort elements according to their keys. This function -is deprecated as keys are now always sorted. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$sort(decr = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{decr}}{\code{logical} if \code{TRUE} sort in decreasing order.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -returns the \code{Dict} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-update}{}}} -\subsection{Method \code{update()}}{ -Add elements of \code{other} to this if the name is -not in the \code{Dict} and update elements with existing names. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$update(other)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{other}}{\code{Iterable} object used to update this.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -returns the updated \code{Dict} object. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-values}{}}} -\subsection{Method \code{values()}}{ -Get \code{Container} values -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$values()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -a copy of all elements in a list -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Dict-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Dict$clone(deep = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} -} diff --git a/DictS3.Rd b/DictS3.Rd deleted file mode 100644 index bc3d47b0..00000000 --- a/DictS3.Rd +++ /dev/null @@ -1,151 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-DictS3.R, R/GroupGenericMath.R, -% R/GroupGenericSummary.R, R/Ops-arithmetic.R, R/Ops-logic.R, R/add.R, -% R/replace.R, R/update.R -\name{DictS3} -\alias{DictS3} -\alias{dict} -\alias{as.dict} -\alias{is.dict} -\title{A Dictionary} -\usage{ -dict(...) - -as.dict(x) - -is.dict(x) -} -\arguments{ -\item{...}{elements put into the \code{Dict}.} - -\item{x}{\code{R} object of \code{ANY} type for \code{\link[=as.dict]{as.dict()}} and \code{\link[=is.dict]{is.dict()}} -or of class \code{Dict} for the \code{S3} methods.} -} -\description{ -The \link{Dict} initially was developed to resemble Python's -dict type, but by now offers both more features and flexibility, for -example, by providing both associative key-value pair as well as -positional array semantics. -It is implemented as a specialized associative \link{Container} thus sharing -all \link{Container} methods with some of them being adapted to account for -the key-value pair semantic. All elements must be named. -} -\details{ -Internally, all key-value pairs are stored in a hash-table and the -elements are sorted lexicographically by their keys. -Methods that alter \code{Dict} objects usually come in two versions -providing either copy or reference semantics where the latter start with -\code{'ref_'} to note the reference semantic, for example, \code{add()} and \code{ref_add()}. - -\itemize{ -\item \code{dict(...)} initializes and returns an object of class \code{Dict} -} - -\itemize{ -\item \code{as.dict(x)} coerces \code{x} to a dictionary -} - -\itemize{ -\item \code{is.dict(x)} returns \code{TRUE} if \code{x} is of class \code{Dict} -and \code{FALSE} otherwise. -} - -\itemize{ -\item \code{x + y} combines \code{x} and \code{y} into a new dict by updating \code{x} -by \code{y} (see also \verb{[update()]}). -} - -\itemize{ -\item \code{x - y} removes all keys from \code{x} that appear in \code{y}. -} - -\itemize{ -\item \code{x} \code{&} \code{y} returns a copy of \code{x} keeping only the keys that -are common in both (key intersection), that is, all keys in \code{x} that do not -exist in \code{y} are removed. -} - -\itemize{ -\item \code{x} \code{|} \code{y} returns a copy of \code{x} extended by all elements of -\code{y} that are stored at keys (or names) that do not exist in \code{x}, thereby -combining the keys of both objects (set union of keys). -} - -\itemize{ -\item \code{add(.x, ...)} and \code{ref_add(.x, ...)} adds \code{key = value} pairs to \code{.x}. -If any of the keys already exists, an error is given. -} - -\itemize{ -\item \code{replace(.x, old, new)} and \code{ref_replace(.x, old)} try to find element \code{old} -and replace it with element \code{new}. If \code{old} does not exist, an error is -raised. -} - -\itemize{ -\item \code{update(object, other)} and \code{ref_update(object, other)} adds elements of \code{other} dict -for keys not yet in \code{object} and replaces the values of existing keys. -} -} -\examples{ -d = dict(b = "one", a = 1, f = mean, na = NA) -print(d) -names(d) - -try(dict(a = 1, 2)) # all elements must be named - -# Coercion -as.dict(list(A = 1:3, B = "b")) -as.dict(c(x = 1, y = "x", z = 2 + 3)) -# Math -d = dict(a = rnorm(1), b = rnorm(1)) -abs(d) -cumsum(d) -round(d) -exp(d) - -# Summary -range(d) -min(d) -max(d) - -d1 = dict(a = 1, b = list(1, 2)) -d2 = dict(a = 2, b = list(1, 2)) -d1 + d2 # same as update(d, d2) -d2 + d1 # same as update(d2, d) -try({ -c(d1, d2) # duplicated keys are not allowed for Dict -}) -d1 - d2 -d2 - d1 -d1 - d1 - -d1 = dict(a = 1, b = 2) -d2 = dict(a = 10, x = 4) -d1 & d2 # {a = 1} - -d1 | d2 # {a = 1, b = 2, x = 4} - - -d = dict(a = 1) -add(d, b = 2, co = container(1:3)) - -try(add(d, a = 7:9)) # key 'a' already in Dict - -d = dict(a = 1, b = "z") -replace(d, 1, 1:5) -replace(d, "z", "a") - -try({ -replace(d, "a", 2) # old element ("a") is not in Dict -}) - -d1 = dict(a = 1, b = 2) -d2 = dict( b = 0, c = 3) -update(d1, d2) # {a = 1, b = 0, c = 3} -update(d2, d1) # {a = 1, b = 2, c = 3} -} -\seealso{ -See \code{\link[=container]{container()}} for all inherited methods. For the full class -documentation see \link{Dict} and it's superclass \link{Container}. -} diff --git a/Iterable.Rd b/Iterable.Rd deleted file mode 100644 index c113cddf..00000000 --- a/Iterable.Rd +++ /dev/null @@ -1,68 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-ContainerR6.R -\docType{class} -\name{Iterable} -\alias{Iterable} -\title{Iterable abstract class interface} -\description{ -An \link{Iterable} is an object that provides an \code{\link[=iter]{iter()}} method, -which is expected to return an \link{Iterator} object. This class defines the -abstract class interface such that each class inheriting this class provides -an \code{\link[=iter]{iter()}} method and must implement a private method \code{create_iter()}, -which must return an \link{Iterator} object. -} -\seealso{ -\link{Iterator} and \link{Container} -} -\author{ -Roman Pahl -} -\section{Methods}{ -\subsection{Public methods}{ -\itemize{ -\item \href{#method-Iterable-new}{\code{Iterable$new()}} -\item \href{#method-Iterable-iter}{\code{Iterable$iter()}} -\item \href{#method-Iterable-clone}{\code{Iterable$clone()}} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterable-new}{}}} -\subsection{Method \code{new()}}{ -\code{Iterable} is an abstract class and thus cannot be instantiated. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterable$new()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterable-iter}{}}} -\subsection{Method \code{iter()}}{ -Create iterator -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterable$iter()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -returns the \code{Iterator} object. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterable-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterable$clone(deep = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} -} diff --git a/Iterator.Rd b/Iterator.Rd deleted file mode 100644 index e4631882..00000000 --- a/Iterator.Rd +++ /dev/null @@ -1,235 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-IteratorR6.R -\docType{class} -\name{Iterator} -\alias{Iterator} -\title{Iterator Class} -\description{ -An \code{Iterator} is an object that allows to iterate over -sequences. It implements \code{next_iter} and \code{get_value} to iterate and retrieve the -value of the sequence it is associated with. -For the standard S3 interface, see \code{\link[=iter]{iter()}}. -} -\examples{ - -# Numeric Vector -v = 1:3 -it = Iterator$new(v) -it - -try(it$get_value()) # iterator does not point at a value - -it$has_value() -it$has_next() -it$next_iter() -it$get_value() -it$get_next() -it$get_next() -it -it$has_next() -it$begin() -it$get_value() -it$reset_iter() - -# Works by reference for Container -co = Container$new(1, 2, 3) -it = co$iter() -it$get_next() -co$discard(2) -it -it$get_value() -co$discard(1) -it -it$get_value() -it$begin() -} -\author{ -Roman Pahl -} -\section{Methods}{ -\subsection{Public methods}{ -\itemize{ -\item \href{#method-Iterator-new}{\code{Iterator$new()}} -\item \href{#method-Iterator-begin}{\code{Iterator$begin()}} -\item \href{#method-Iterator-get_value}{\code{Iterator$get_value()}} -\item \href{#method-Iterator-get_next}{\code{Iterator$get_next()}} -\item \href{#method-Iterator-has_next}{\code{Iterator$has_next()}} -\item \href{#method-Iterator-has_value}{\code{Iterator$has_value()}} -\item \href{#method-Iterator-length}{\code{Iterator$length()}} -\item \href{#method-Iterator-pos}{\code{Iterator$pos()}} -\item \href{#method-Iterator-next_iter}{\code{Iterator$next_iter()}} -\item \href{#method-Iterator-print}{\code{Iterator$print()}} -\item \href{#method-Iterator-reset_iter}{\code{Iterator$reset_iter()}} -\item \href{#method-Iterator-clone}{\code{Iterator$clone()}} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-new}{}}} -\subsection{Method \code{new()}}{ -\code{Iterator} constructor -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$new(x, .subset = .subset2)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{x}}{object to iterate over} - -\item{\code{.subset}}{accessor function} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -invisibly returns the \code{Iterator} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-begin}{}}} -\subsection{Method \code{begin()}}{ -set iterator to the first element of the underlying -sequence unless length of sequence is zero, in which case it will -point to nothing. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$begin()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -invisibly returns the \code{Iterator} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-get_value}{}}} -\subsection{Method \code{get_value()}}{ -get value where the iterator points to -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$get_value()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -returns the value the \code{Iterator} is pointing at. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-get_next}{}}} -\subsection{Method \code{get_next()}}{ -get next value -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$get_next()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -increments the iterator and returns the value the \code{Iterator} -is pointing to. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-has_next}{}}} -\subsection{Method \code{has_next()}}{ -check if \code{iterator} has more elements -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$has_next()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -\code{TRUE} if \code{iterator} has next element else \code{FALSE} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-has_value}{}}} -\subsection{Method \code{has_value()}}{ -check if \code{iterator} points at value -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$has_value()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -\code{TRUE} if \code{iterator} points at value otherwise \code{FALSE} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-length}{}}} -\subsection{Method \code{length()}}{ -iterator length -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$length()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -number of elements to iterate -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-pos}{}}} -\subsection{Method \code{pos()}}{ -get iterator position -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$pos()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -\code{integer} if \code{iterator} has next element else \code{FALSE} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-next_iter}{}}} -\subsection{Method \code{next_iter()}}{ -increment \code{iterator} -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$next_iter()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -invisibly returns the \code{Iterator} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-print}{}}} -\subsection{Method \code{print()}}{ -print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$print()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-reset_iter}{}}} -\subsection{Method \code{reset_iter()}}{ -reset iterator to '0' -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$reset_iter()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -invisibly returns the \code{Iterator} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Iterator-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Iterator$clone(deep = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} -} diff --git a/NEWS.md b/NEWS.md index e755eadd..5443d57e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# container 1.0.4 + +* fix "don't run" examples +* fix Rd files regarding tidy HTML + # container 1.0.1 * prevent duplicated column names when renaming dict.tables diff --git a/OpsArithmetic.Rd b/OpsArithmetic.Rd deleted file mode 100644 index 60ebdd21..00000000 --- a/OpsArithmetic.Rd +++ /dev/null @@ -1,103 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/Ops-arithmetic.R -\name{OpsArithmetic} -\alias{OpsArithmetic} -\alias{+.Container} -\alias{-.Container} -\alias{+.Deque} -\alias{-.Deque} -\alias{+.Dict} -\alias{-.Dict} -\alias{+.Set} -\alias{-.Set} -\title{Arithmetic Operators} -\usage{ -\method{+}{Container}(x, y) - -\method{-}{Container}(x, y) - -\method{+}{Deque}(x, y) - -\method{-}{Deque}(x, y) - -\method{+}{Dict}(x, y) - -\method{-}{Dict}(x, y) - -\method{+}{Set}(x, y) - -\method{-}{Set}(x, y) -} -\arguments{ -\item{x, y}{Depending on the operator at least one must be of class -\code{\link[=Container]{Container()}} or the respective derived class and the other at least be -coercible to the respective class.} -} -\value{ -For \code{Container}, \code{x + y} combines \code{x} and \code{y} into a new container -by appending \code{y} to \code{x}. - -For Container, \code{x - y} element-wise discards all items of \code{y} -from \code{x}, given the element was contained in \code{x}. The result is always a -container. - -For \verb{Deque,} \code{x + y} combines \code{x} and \code{y} into a new deque by -appending \code{y} to \code{x}. - -For Deque, \code{x - y} element-wise removes all items of \code{y} from \code{x}, -given the element was contained in \code{x}. - -For \code{Dict}, \code{x + y} combines \code{x} and \code{y} into a new dict by -updating \code{x} by \code{y} (see also \verb{[update()]}). - -For \code{Dict}, \code{x - y} removes all keys from \code{x} that appear in \code{y}. - -For \code{Set}, \code{x + y} performs the set union. - -For \code{Set}, \code{x - y} performs the set difference. -} -\description{ -Binary arithmetic operators for \code{\link[=Container]{Container()}} objects and -derived classes. -} -\examples{ -c1 = container(1, 1:2) -c2 = container(2, 1:2) -c1 + c2 # same as c(c1, c2) -c2 + c1 # same as c(c2, c1) - -c1 - c2 -c2 - c1 -c1 - c1 -# Arithmetic -d1 = deque(1, 1:2) -d2 = deque(2, 1:2) -d1 + d2 # same as c(d1, d2) -d2 + d1 # same as c(d2, d1) - -d1 - d2 -d2 - d1 -d1 - d1 - -# Arithmetic -d1 = dict(a = 1, b = list(1, 2)) -d2 = dict(a = 2, b = list(1, 2)) -d1 + d2 # same as update(d, d2) -d2 + d1 # same as update(d2, d) -try({ -c(d1, d2) # duplicated keys are not allowed for Dict -}) -d1 - d2 -d2 - d1 -d1 - d1 - -# Arithmetic -s1 = setnew(1, 1:2) -s2 = setnew(2, 1:2) -s1 + s2 # same as s1 | s2 or c(c1, s2) -s2 + s1 # same - -s1 - s2 -s2 - s1 - -} diff --git a/OpsCompare.Rd b/OpsCompare.Rd deleted file mode 100644 index 2400d7a6..00000000 --- a/OpsCompare.Rd +++ /dev/null @@ -1,54 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/Ops-compare.R -\name{OpsCompare} -\alias{OpsCompare} -\alias{==.Container} -\alias{!=.Container} -\alias{<.Container} -\alias{>.Container} -\alias{<=.Container} -\alias{>=.Container} -\title{Comparison Operators} -\usage{ -\method{==}{Container}(x, y) - -\method{!=}{Container}(x, y) - -\method{<}{Container}(x, y) - -\method{>}{Container}(x, y) - -\method{<=}{Container}(x, y) - -\method{>=}{Container}(x, y) -} -\arguments{ -\item{x, y}{at least one must be a \code{\link[=Container]{Container()}} object (or an object of -one of the derived classes) while the other must be at least iterable.} -} -\description{ -Binary comparison operators for \code{\link[=Container]{Container()}} objects and -derived classes. -} -\details{ -\itemize{ -\item \code{x == y} is \code{TRUE} if the contents of \code{x} and \code{y} are lexicographically \emph{equal}. -\item \code{x != y} is \code{TRUE} if the contents of \code{x} and \code{y} are \emph{not equal}. -\item \code{x < y} is \code{TRUE} if the contents of x are lexicographically \emph{less} than the -contents of y. -\item \code{x <= y} is \code{TRUE} if the contents of x are lexicographically \emph{less} than -or \emph{equal} to the contents of y. -} -} -\examples{ -c1 = container(1, 2, 3) -c2 = container(1, 3, 2) -c1 == c1 # TRUE -c1 != c2 # TRUE -c1 <= c1 # TRUE -c1 == c2 # FALSE -c1 < c2 # TRUE -c1 < container(2) # TRUE -c1 < container() # FALSE - -} diff --git a/OpsExtract.Rd b/OpsExtract.Rd deleted file mode 100644 index d6c249b2..00000000 --- a/OpsExtract.Rd +++ /dev/null @@ -1,43 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/Ops-extract.R -\name{OpsExtract} -\alias{OpsExtract} -\alias{[.Container} -\alias{[[.Container} -\title{Extract Parts of a Container Object} -\usage{ -\method{[}{Container}(x, ...) - -\method{[[}{Container}(x, i) -} -\arguments{ -\item{x}{\code{Container} object from which to extract elements.} - -\item{i, ...}{indices specifying elements to extract. Indices -are \code{numeric} or \code{character} vectors or a \code{list} containing both.} -} -\description{ -Extract parts of a \code{Container} object similar -to R's base extract operators on lists. -} -\details{ -\code{[} selects multiple values. The indices can be \code{numeric} or -\code{character} or both. They can be passed as a \code{vector} or \code{list} or, -for convenience, just as a comma-separated sequence (see Examples). -Non-existing indices are ignored. - -\code{[[} selects a single value using a \code{numeric} or \code{character} index. -} -\examples{ -co = container(a = 1, b = 2, c = 3, d = 4) -co[1:2] -co[1, 4] -co["d", 2] -co[list("d", 2)] -co[0:10] - -co = container(a = 1, b = 2) -co[[1]] -co[["a"]] -co[["x"]] -} diff --git a/OpsLogic.Rd b/OpsLogic.Rd deleted file mode 100644 index 55184c04..00000000 --- a/OpsLogic.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/Ops-logic.R -\name{OpsLogic} -\alias{OpsLogic} -\alias{&.Dict} -\alias{|.Dict} -\alias{&.Set} -\alias{|.Set} -\title{Logic Operators} -\usage{ -\method{&}{Dict}(x, y) - -\method{|}{Dict}(x, y) - -\method{&}{Set}(x, y) - -\method{|}{Set}(x, y) -} -\arguments{ -\item{x, y}{Depending on the operator at least one must be of class -\code{\link[=Container]{Container()}} or the respective derived class and the other at least be -coercible to the respective class.} -} -\description{ -Binary logic operators for \code{\link[=Container]{Container()}} objects and -derived classes. -} -\examples{ -d1 = dict(a = 1, b = 2) -d2 = dict(a = 10, x = 4) -d1 & d2 # {a = 1} - -} diff --git a/OpsReplace.Rd b/OpsReplace.Rd deleted file mode 100644 index 2b4376bb..00000000 --- a/OpsReplace.Rd +++ /dev/null @@ -1,69 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/Ops-replace.R -\name{OpsReplace} -\alias{OpsReplace} -\alias{[<-.Container} -\alias{[[<-.Container} -\alias{$<-.Container} -\title{Replace Parts of a Container} -\usage{ -\method{[}{Container}(x, i) <- value - -\method{[[}{Container}(x, i) <- value - -\method{$}{Container}(x, name) <- value -} -\arguments{ -\item{x}{\code{Container} object in which to replace elements.} - -\item{i}{indices specifying elements to replace. Indices -are \code{numeric} or \code{character} vectors or a \code{list} containing both.} - -\item{value}{the replacing value of \code{ANY} type} - -\item{name}{\code{character} string (possibly backtick quoted)} -} -\description{ -Replace parts of a \code{Container} object similar -to R's base replace operators on lists. -} -\details{ -\verb{[<-} replaces multiple values. The indices can be \code{numeric} or -\code{character} or both. They can be passed as a \code{vector} or \code{list}. Values can -be added by 'replacing' at new indices, which only works for \code{character} -indices. - -\verb{[[<-} replaces a single value at a given \code{numeric} or \code{character} index. -Instead of an index, it is also possible to replace certain elements by -passing the element in curly braces (see Examples), that is, the object is -searched for the element and then the element is replaced by the value. - -\verb{$<-} replaces a single element at a given name. -} -\examples{ -co = container(a = 1, b = "bar") -(co[1:2] <- 1:2) - -try({ -co[3] <- 3 # index out of range -}) -(co[list(1, "b")] <- 3:4) # mixed numeric/character index - -co = container(a = 1, b = 2) -co[[1]] <- 9 -co[["b"]] <- 8 -co[["x"]] <- 7 -co$z <- 99 -print(co) - -# Replace 8 by 0 -co[[{8}]] <- 0 -print(co) - - -co = container(a = 1, b = "bar") -co$f <- 3 -co$b <- 2 -co - -} diff --git a/OrderedSet.Rd b/OrderedSet.Rd deleted file mode 100644 index fedafd28..00000000 --- a/OrderedSet.Rd +++ /dev/null @@ -1,138 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-SetR6.R -\name{OrderedSet} -\alias{OrderedSet} -\title{OrderedSet Class} -\description{ -The \link{OrderedSet} is a \link{Set} where all elements are always -ordered. -} -\details{ -The order of elements is determined sequentially as follows: -\itemize{ -\item element's length -\item whether it is an atomic element -\item the element's class(es) -\item by numeric value (if applicable) -\item it's representation when printed -\item the name of the element in the \link{Set} -} -} -\examples{ -s1 = OrderedSet$new(2, 1) -s1 -} -\seealso{ -\link{Container}, \link{Set} -} -\section{Super classes}{ -\code{\link[container:Iterable]{container::Iterable}} -> \code{\link[container:Container]{container::Container}} -> \code{\link[container:Set]{container::Set}} -> \code{OrderedSet} -} -\section{Methods}{ -\subsection{Public methods}{ -\itemize{ -\item \href{#method-OrderedSet-new}{\code{OrderedSet$new()}} -\item \href{#method-OrderedSet-add}{\code{OrderedSet$add()}} -\item \href{#method-OrderedSet-clone}{\code{OrderedSet$clone()}} -} -} -\if{html}{\out{ -
Inherited methods - -
-}} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-OrderedSet-new}{}}} -\subsection{Method \code{new()}}{ -\code{OrderedSet} constructor -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{OrderedSet$new(...)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{...}}{initial elements put into the \code{OrderedSet}} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -returns the \code{OrderedSet} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-OrderedSet-add}{}}} -\subsection{Method \code{add()}}{ -Add element -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{OrderedSet$add(value, name = NULL)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{value}}{value of \code{ANY} type to be added to the \code{OrderedSet}.} - -\item{\code{name}}{\code{character} optional name attribute of the value.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{OrderedSet} object. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-OrderedSet-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{OrderedSet$clone(deep = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} -} diff --git a/Set.Rd b/Set.Rd deleted file mode 100644 index 8dd5c3d6..00000000 --- a/Set.Rd +++ /dev/null @@ -1,276 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-SetR6.R -\name{Set} -\alias{Set} -\title{Set Class} -\description{ -The \link{Set} is considered and implemented as a specialized -\link{Container}, that is, elements are always unique in the \link{Container} and -it provides typical set operations such as \code{union} and \code{intersect}. -For the standard S3 interface, see \code{\link[=setnew]{setnew()}}. -} -\examples{ -s1 = Set$new(1, 2) -s1 -s1$add(1) -s1$add(3) -s2 = Set$new(3, 4, 5) -s1$union(s2) -s1 - -s1 = Set$new(1, 2, 3) -s1$intersect(s2) -s1 - -s1$diff(s2) -s1$diff(s1) -s1 -} -\seealso{ -\link{Container}, \code{\link[=set]{set()}} -} -\section{Super classes}{ -\code{\link[container:Iterable]{container::Iterable}} -> \code{\link[container:Container]{container::Container}} -> \code{Set} -} -\section{Methods}{ -\subsection{Public methods}{ -\itemize{ -\item \href{#method-Set-new}{\code{Set$new()}} -\item \href{#method-Set-add}{\code{Set$add()}} -\item \href{#method-Set-diff}{\code{Set$diff()}} -\item \href{#method-Set-intersect}{\code{Set$intersect()}} -\item \href{#method-Set-union}{\code{Set$union()}} -\item \href{#method-Set-is_equal}{\code{Set$is_equal()}} -\item \href{#method-Set-is_subset}{\code{Set$is_subset()}} -\item \href{#method-Set-is_proper_subset}{\code{Set$is_proper_subset()}} -\item \href{#method-Set-values}{\code{Set$values()}} -\item \href{#method-Set-clone}{\code{Set$clone()}} -} -} -\if{html}{\out{ -
Inherited methods - -
-}} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-new}{}}} -\subsection{Method \code{new()}}{ -\code{Set} constructor -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$new(...)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{...}}{initial elements put into the \code{Set}} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -returns the \code{Set} object -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-add}{}}} -\subsection{Method \code{add()}}{ -Add element -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$add(value, name = NULL)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{value}}{value of \code{ANY} type to be added to the \code{Set}.} - -\item{\code{name}}{\code{character} optional name attribute of the value.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Set} object. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-diff}{}}} -\subsection{Method \code{diff()}}{ -\code{Set} difference -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$diff(s)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{s}}{\code{Set} object to 'subtract'} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Set} object updated as a result of the set difference -between this and s. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-intersect}{}}} -\subsection{Method \code{intersect()}}{ -\code{Set} intersection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$intersect(s)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{s}}{\code{Set} object to 'intersect'} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Set} object as a result of the intersection of this and s. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-union}{}}} -\subsection{Method \code{union()}}{ -\code{Set} union -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$union(s)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{s}}{\code{Set} object to be 'unified'} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -the \code{Set} object as a result of the union of this and s. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-is_equal}{}}} -\subsection{Method \code{is_equal()}}{ -\code{Set} equality -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$is_equal(s)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{s}}{\code{Set} object to compare against} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{TRUE} if this is equal to \code{s}, otherwise \code{FALSE} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-is_subset}{}}} -\subsection{Method \code{is_subset()}}{ -\code{Set} proper subset -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$is_subset(s)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{s}}{\code{Set} object to compare against} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{TRUE} if this is subset of \code{s}, otherwise \code{FALSE} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-is_proper_subset}{}}} -\subsection{Method \code{is_proper_subset()}}{ -\code{Set} subset -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$is_proper_subset(s)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{s}}{\code{Set} object to compare against} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\code{TRUE} if this is proper subset of \code{s}, otherwise \code{FALSE} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-values}{}}} -\subsection{Method \code{values()}}{ -Get \code{Set} values -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$values()}\if{html}{\out{
}} -} - -\subsection{Returns}{ -elements of the set as a base list -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Set-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Set$clone(deep = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} -} diff --git a/SetS3.Rd b/SetS3.Rd deleted file mode 100644 index 4668b2e2..00000000 --- a/SetS3.Rd +++ /dev/null @@ -1,115 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-SetS3.R, R/GroupGenericMath.R, -% R/GroupGenericSummary.R, R/Ops-arithmetic.R, R/Ops-logic.R -\name{SetS3} -\alias{SetS3} -\alias{setnew} -\alias{as.set} -\alias{as.orderedset} -\alias{is.set} -\alias{is.orderedset} -\title{Set and ordered Set} -\usage{ -setnew(..., .ordered = FALSE) - -as.set(x) - -as.orderedset(x) - -is.set(x) - -is.orderedset(x) -} -\arguments{ -\item{...}{initial elements put into the \code{Set}.} - -\item{.ordered}{\code{logical} if \code{TRUE} all elements in the \link{Set} will be -ordered.} - -\item{x}{\code{R} object of \code{ANY} type for \code{\link[=as.set]{as.set()}} and \code{\link[=is.set]{is.set()}} -or of class \code{Set} for the \code{S3} methods.} -} -\description{ -The \link{Set} is considered and implemented as a specialized -\link{Container}, that is, \code{Set} elements are always unique. It provides -typical set operations such as \code{union} and \code{intersect}. -} -\details{ -Methods that alter \link{Set} objects usually come in two versions -providing either copy or reference semantics where the latter start with -\code{'ref_'} to note the reference semantic, for example, \code{\link[=add]{add()}} and \code{\link[=ref_add]{ref_add()}}. - -\itemize{ -\item \code{setnew(...)} initializes and returns a \code{\link[=Set]{Set()}} object. -} - -\itemize{ -\item \code{as.set(x)} coerces \code{x} to a set. -} - -\itemize{ -\item \code{as.orderedset(x)} coerces \code{x} to an ordered set. -} - -\itemize{ -\item \code{is.set(x)} returns \code{TRUE} if \code{x} is of class \code{Set} and \code{FALSE} -otherwise. -} - -\itemize{ -\item \code{is.orderedset(x)} returns \code{TRUE} if \code{x} is of class \code{OrderedSet} -and \code{FALSE} otherwise. -} - -\itemize{ -\item \code{x} \code{&} \code{y} performs the set intersection of x and y -} - -\itemize{ -\item \code{x} \code{|} \code{y} performs the set union of x and y -} -} -\examples{ -s = setnew(1, b = NA, 1:3, c = container("a", 1)) -is.set(s) -print(s) -length(s) -names(s) -as.list(s) -unpack(s) # flatten recursively similar to unlist - -so = setnew(2, 1, .ordered = TRUE) -print(so) -add(so, 0) -# Math -s = setnew(5:3, 1, 2) -s -abs(s) -cumsum(s) -round(s) -exp(s) - -# Summary -range(s) -min(s) -max(s) - -s1 = setnew(1, 1:2) -s2 = setnew(2, 1:2) -s1 + s2 # same as s1 | s2 or c(c1, s2) -s2 + s1 # same - -s1 - s2 -s2 - s1 - -s1 = setnew(1, b = 2) -s2 = setnew(1, b = 4) -s1 & s2 # {1} - -s1 | s2 # {1, b = 2, b = 4} - -} -\seealso{ -See \code{\link[=container]{container()}} for all inherited methods. For the full class -documentation see \link{Set} and it's superclass \link{Container}. -} diff --git a/add.Rd b/add.Rd deleted file mode 100644 index eee319f0..00000000 --- a/add.Rd +++ /dev/null @@ -1,77 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/add.R -\name{add} -\alias{add} -\alias{ref_add} -\alias{add.Container} -\alias{ref_add.Container} -\alias{add.Dict} -\alias{ref_add.Dict} -\alias{add.dict.table} -\alias{ref_add.dict.table} -\title{Add Elements to Containers} -\usage{ -add(.x, ...) - -ref_add(.x, ...) - -\method{add}{Container}(.x, ...) - -\method{ref_add}{Container}(.x, ...) - -\method{add}{Dict}(.x, ...) - -\method{ref_add}{Dict}(.x, ...) - -\method{add}{dict.table}(.x, ...) - -\method{ref_add}{dict.table}(.x, ...) -} -\arguments{ -\item{.x}{an \code{R} object of the respective class.} - -\item{...}{elements to be added.} -} -\value{ -For \link{Container}, an object of class \link{Container} (or one of the -respective derived classes). - -For \link{dict.table} an object of class -\link{dict.table}. -} -\description{ -Add elements to container-like objects. -} -\note{ -While \link{add} uses copy semantics \link{ref_add} works by reference. - -If \code{.x} is a \link{Container}, \link{Set} or \link{Deque} object, the elements being added -can (but must not) be named. - -If \code{.x} is a \link{Dict} or \link{dict.table} object, -all elements \emph{must} be of the form \code{key = value}. -If one of the keys already exists, an error is given. -} -\examples{ - -co = container(1) -add(co, 1, b = 2, c = container(1:3)) - -s = setnew(1) -add(s, 1, 1, b = 2, "1", co = container(1, 1)) - -d = dict(a = 1) -add(d, b = 2, co = container(1:3)) - -try(add(d, a = 7:9)) # key 'a' already in Dict - -dit = dict.table(a = 1:3) -add(dit, b = 3:1, d = 4:6) - -try(add(dit, a = 7:9)) # column 'a' already exists - -dit = dict.table(a = 1:3) -add(dit, b = 3:1, d = 4:6) - -try(add(dit, a = 7:9)) # column 'a' already exists -} diff --git a/addleft.Rd b/addleft.Rd deleted file mode 100644 index 8221ed32..00000000 --- a/addleft.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/addleft.R -\name{addleft} -\alias{addleft} -\alias{ref_addleft} -\alias{addleft.Deque} -\alias{ref_addleft.Deque} -\title{Add Elements to the Left of Deques} -\usage{ -addleft(.x, ...) - -ref_addleft(.x, ...) - -\method{addleft}{Deque}(.x, ...) - -\method{ref_addleft}{Deque}(.x, ...) -} -\arguments{ -\item{.x}{a \verb{[Deque]} object} - -\item{...}{elements to be added.} -} -\value{ -For \link{Deque}, an object of class \link{Deque} with the elements being -added to the left of \code{.x}. -} -\description{ -Add elements to left side of \link{Deque} objects. -} -\note{ -While \link{addleft} uses copy semantics \link{ref_addleft} work by reference. -} -\examples{ -d = deque(0) -add(d, a = 1, b = 2) # |0, a = 1, b = 2| -addleft(d, a = 1, b = 2) # |b = 2, a = 1, 0| -} diff --git a/at.Rd b/at.Rd deleted file mode 100644 index 82fc3783..00000000 --- a/at.Rd +++ /dev/null @@ -1,57 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/at.R -\name{at} -\alias{at} -\alias{at.Container} -\alias{at.dict.table} -\title{Extract Elements Safely} -\usage{ -at(.x, ...) - -\method{at}{Container}(.x, ...) - -\method{at}{dict.table}(.x, ...) -} -\arguments{ -\item{.x}{an \code{R} object of the respective class.} - -\item{...}{indices of elements to be extracted} -} -\value{ -For \code{Container}, returns the values at the given indidces. - -For \code{dict.table}, returns the columns at the given indices. -} -\description{ -Extract parts of a Container at given indices. If an index is invalid, an -error is signaled. If given as a string, the element matching the -name is returned. If there are two or more identical names, the value of the -first match (i.e. \emph{leftmost} element) is returned. Indices can be letters or -numbers, or both at the same time. -} -\examples{ - -# Container -co = container(a = 1, 2, b = 3, 4) -at(co, 1:3) -at(co, "a", "b", 2) -try(at(co, "x")) # index 'x' not found -try(at(co, 1:10)) # index 5 exceeds length of Container -# Dict -d = dict(a = 1, b = 3) -at(d, 1:2) -at(d, "a", 2) -try(at(d, "x")) # index 'x' not found -try(at(d, 1:3)) # index 5 exceeds length of Dict - -# dict.table -dit = dict.table(a = 1:3, b = 4:6) -at(dit, "a") -at(dit, 2) -at(dit, "a", 2) -try(at(dit, "x")) # index 'x' not found -try(at(dit, 1:3)) # index 3 exceeds length of dict.table -} -\seealso{ -\code{\link[=peek_at]{peek_at()}} for less strict extraction -} diff --git a/at2.Rd b/at2.Rd deleted file mode 100644 index ecc0333b..00000000 --- a/at2.Rd +++ /dev/null @@ -1,66 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/at2.R -\name{at2} -\alias{at2} -\alias{at2.Container} -\alias{at2.dict.table} -\title{Extract Single Elements Safely} -\usage{ -at2(x, ...) - -\method{at2}{Container}(x, index, ...) - -\method{at2}{dict.table}(x, index, ...) -} -\arguments{ -\item{x}{an \code{R} object of the respective class.} - -\item{...}{other arguments passed to or from methods.} - -\item{index}{\code{character} name or \code{numeric} position of the sought value.} -} -\value{ -For \code{Container}, returns the value at the given index. - -For \code{dict.table}, returns the column at the given \code{index} or signals -an error if not found. -} -\description{ -Extracts the value of a Container at the given index. If the index is -invalid, an error is signaled. If given as a string, the element matching the -name is returned. If there are two or more identical names, the value of the -first match (i.e. \emph{leftmost} element) is returned. -Extract value at index. If index is invalid or not found, an error is -signaled. If given as a string, the element matching the name is returned. -If there are two or more identical names, the value of the first match (i.e. -\emph{leftmost} element) is returned. -} -\examples{ - -# Container -co = container(a = 1, 2, b = 3, 4) -at2(co, 1) -at2(co, "a") -at2(co, 2) -try(at2(co, "x")) # index 'x' not found -try(at2(co, 5)) # index 5 exceeds length of Container - -# Dict -d = dict(a = 1, b = 3) -at2(d, 1) -at2(d, "a") -at2(d, 2) -try(at2(d, "x")) # index 'x' not found -try(at2(d, 5)) # index 5 exceeds length of Dict - -# dict.table -dit = dict.table(a = 1:3, b = 4:6) -at2(dit, 1) -at2(dit, "a") -at2(dit, 2) -try(at2(dit, "x")) # index 'x' not found -try(at2(dit, 5)) # index 5 exceeds length of dict.table -} -\seealso{ -\code{\link[=peek_at2]{peek_at2()}} for less strict extraction -} diff --git a/clear.Rd b/clear.Rd deleted file mode 100644 index 2696c827..00000000 --- a/clear.Rd +++ /dev/null @@ -1,50 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/clear.R -\name{clear} -\alias{clear} -\alias{ref_clear} -\alias{clear.Container} -\alias{ref_clear.Container} -\alias{clear.dict.table} -\alias{ref_clear.dict.table} -\title{Clear a Container} -\usage{ -clear(x) - -ref_clear(x) - -\method{clear}{Container}(x) - -\method{ref_clear}{Container}(x) - -\method{clear}{dict.table}(x) - -\method{ref_clear}{dict.table}(x) -} -\arguments{ -\item{x}{any \code{R} object.} -} -\value{ -For \link{Container}, an object of class \link{Container} (or one of the -respective derived classes). - -For \link{dict.table} an object of class -\link{dict.table}. -} -\description{ -Removes all elements from the container object. -} -\examples{ - -co = container(1, 2, mean) -clear(co) -co -ref_clear(co) -co - -dit = dict.table(a = 1, b = 2) -clear(dit) -dit # original was not touched -ref_clear(dit) -dit # original was cleared -} diff --git a/clone.Rd b/clone.Rd deleted file mode 100644 index e8fd0b2b..00000000 --- a/clone.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/clone.R -\name{clone} -\alias{clone} -\alias{clone.Container} -\alias{clone.dict.table} -\title{Clone an Object} -\usage{ -clone(x) - -\method{clone}{Container}(x) - -\method{clone}{dict.table}(x) -} -\arguments{ -\item{x}{any \code{R} object.} -} -\value{ -A copy of the object. -} -\description{ -Creates a copy of the object. -} -\examples{ - -co = container(1, 2, 3) -co2 = clone(co) -co == co2 - -d = dict.table(a = 1:2, b = 3:4) -d2 = clone(d) -ref_clear(d) -print(d2) -} diff --git a/container_options.Rd b/container_options.Rd deleted file mode 100644 index 8373926b..00000000 --- a/container_options.Rd +++ /dev/null @@ -1,69 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/options.R -\name{container_options} -\alias{container_options} -\alias{getContainerOption} -\title{Set Container Package Options} -\usage{ -container_options(..., .reset = FALSE) - -getContainerOption(x, default = NULL) -} -\arguments{ -\item{...}{any options can be defined, using name = value.} - -\item{.reset}{\code{logical} if \code{TRUE}, the options are reset to their default and -returned.} - -\item{x}{a character string holding an option name.} - -\item{default}{if the specified option is not set in the options list, this -value is returned.} -} -\value{ -\itemize{ -\item \code{container_options()} returns a list of all set options sorted by name. -\item \code{container_options(name)}, a list of length one containing the set value, -or \code{NULL} if it is unset. Can also be multiple names (see Examples). -\item \code{container_options(key = value)} sets the option with name \code{key} to \code{value} -and returns the previous options invisibly. -} -} -\description{ -Set Container Package Options -} -\section{Container Options}{ - -\itemize{ -\item \code{compare} (default = \code{all.equal}) -\item \code{useDots} (default = \code{TRUE}) whether to abbreviate long container -elements with \code{...} when exceeding \code{vec.len} (see below). If \code{FALSE}, they -are abbreviated as \verb{<>}. -\item \code{vec.len} (default = 4) the length limit at which container vectors are -abbreviated. -} -} - -\examples{ -co = container(1L, 1:10, as.list(1:5)) -co - -container_options(useDots = FALSE) -co - -container_options(useDots = TRUE, vec.len = 6) -co - -has(co, 1.0) - -container_options(compare = "identical") - -has(co, 1.0) # still uses 'all.equal' - -co2 = container(1L) -has(co2, 1.0) -has(co2, 1L) - -container_options() -container_options(.reset = TRUE) -} diff --git a/count.Rd b/count.Rd deleted file mode 100644 index 3030dd7d..00000000 --- a/count.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/count.R -\name{count} -\alias{count} -\alias{count.Container} -\alias{count.Set} -\title{Count Elements} -\usage{ -count(x, elem) - -\method{count}{Container}(x, elem) - -\method{count}{Set}(x, elem) -} -\arguments{ -\item{x}{any \code{R} object.} - -\item{elem}{element to counted.} -} -\value{ -\code{integer} number of how many times \code{elem} occurs in the object. -} -\description{ -Count the number of occurences of some element. -} -\examples{ - -co = container("a", "b", "a", mean, mean) -count(co, "a") -count(co, mean) -count(co, "c") -} diff --git a/delete.Rd b/delete.Rd deleted file mode 100644 index 1d3102cd..00000000 --- a/delete.Rd +++ /dev/null @@ -1,40 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/delete.R -\name{delete} -\alias{delete} -\alias{ref_delete} -\alias{delete.Container} -\alias{ref_delete.Container} -\title{Delete Container Elements Safely} -\usage{ -delete(.x, ...) - -ref_delete(.x, ...) - -\method{delete}{Container}(.x, ...) - -\method{ref_delete}{Container}(.x, ...) -} -\arguments{ -\item{.x}{any \code{R} object.} - -\item{...}{elements to be deleted.} -} -\value{ -For \code{Container}, an object of class \code{Container} (or one of the -respective derived classes). -} -\description{ -Search and remove elements from an object. If the element is not found, -an error is signaled. -} -\examples{ - -s = setnew("a", 1:3, iris) -print(s) -delete(s, 1:3, "a") -delete(s, iris) -try({ -delete(s, "b") # "b" is not in Set -}) -} diff --git a/delete_at.Rd b/delete_at.Rd deleted file mode 100644 index 2c6c932a..00000000 --- a/delete_at.Rd +++ /dev/null @@ -1,58 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/delete_at.R -\name{delete_at} -\alias{delete_at} -\alias{ref_delete_at} -\alias{delete_at.Container} -\alias{ref_delete_at.Container} -\alias{delete_at.dict.table} -\alias{ref_delete_at.dict.table} -\title{Delete Elements at Indices Safely} -\usage{ -delete_at(.x, ...) - -ref_delete_at(.x, ...) - -\method{delete_at}{Container}(.x, ...) - -\method{ref_delete_at}{Container}(.x, ...) - -\method{delete_at}{dict.table}(.x, ...) - -\method{ref_delete_at}{dict.table}(.x, ...) -} -\arguments{ -\item{.x}{any \code{R} object.} - -\item{...}{indices at which values are to be deleted.} -} -\value{ -For \code{Container}, an object of class \code{Container} (or one of the -respective derived classes). - -For \code{dict.table}, an object of class \code{dict.table}. -} -\description{ -Search and remove values at given indices, which can be numeric or character -or both. If any given index is invalid, an error is signaled. Indices can be -numbers or names or both. -} -\examples{ - -co = container(a = 1, b = 2, 3) -delete_at(co, "a", "b") # [3] -delete_at(co, 1:2) # [3] -delete_at(co, "a", 3) # [b = 2] -try({ -delete_at(co, 4) # index out of range -delete_at(co, "x") # names(s) not found: 'x' -}) - -dit = as.dict.table(head(sleep)) -dit -delete_at(dit, "ID") -delete_at(dit, "ID", 1) -try({ - delete_at(dit, "foo") # Column 'foo' not in dict.table -}) -} diff --git a/deprecated.Rd b/deprecated.Rd deleted file mode 100644 index 2cbab9ee..00000000 --- a/deprecated.Rd +++ /dev/null @@ -1,56 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/container-deprecated.R -\name{deprecated} -\alias{deprecated} -\alias{empty} -\alias{empty.Container} -\alias{size} -\alias{size.Container} -\alias{sortkey} -\alias{sortkey.Dict} -\alias{values} -\alias{values.Container} -\alias{values.dict.table} -\alias{keys} -\title{Deprecated Functions} -\usage{ -empty(x) - -\method{empty}{Container}(x) - -size(x) - -\method{size}{Container}(x) - -sortkey(x, decr = FALSE) - -\method{sortkey}{Dict}(x, decr = FALSE) - -values(x) - -\method{values}{Container}(x) - -\method{values}{dict.table}(x) - -keys(x) -} -\arguments{ -\item{x}{any \code{R} object.} - -\item{decr}{\code{logical} sort decreasingly?} -} -\description{ -These functions are provided for backwards-compatibility and -may be defunct as soon as the next release. -} -\details{ -\itemize{ -\item \code{\link[=empty]{empty()}} \code{\link[=is_empty]{is_empty()}} instead -\item \code{\link[=set]{set()}} \code{\link[=setnew]{setnew()}} instead -\item \code{\link[=size]{size()}} use \code{\link[=length]{length()}} instead -\item \code{\link[=sortkey]{sortkey()}} keys of \link{Dict} objects are now always sorted -\item \code{\link[=remove]{remove()}} use \code{\link[=delete]{delete()}} instead -\item \code{\link[=type]{type()}} not of use anymore -\item \code{\link[=values]{values()}} use \code{\link[=as.list]{as.list()}} instead -} -} diff --git a/dict.table.Rd b/dict.table.Rd deleted file mode 100644 index a53e05d0..00000000 --- a/dict.table.Rd +++ /dev/null @@ -1,309 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-dict.table.R, R/add.R, R/at.R, -% R/at2.R, R/clear.R, R/clone.R, R/delete_at.R, R/discard_at.R, R/has.R, -% R/has_name.R, R/is_empty.R, R/peek_at.R, R/peek_at2.R, R/pop.R, R/rename.R, -% R/replace_at.R, R/update.R -\name{dict.table} -\alias{dict.table} -\alias{as.dict.table} -\alias{as.dict.table.data.table} -\alias{is.dict.table} -\alias{rbind.dict.table} -\alias{cbind.dict.table} -\title{Combining Dict and data.table} -\usage{ -dict.table(...) - -as.dict.table(x, ...) - -\method{as.dict.table}{data.table}(x, copy = TRUE, ...) - -is.dict.table(x) - -\method{rbind}{dict.table}(x, ...) - -\method{cbind}{dict.table}(x, ...) -} -\arguments{ -\item{...}{elements put into the \link{dict.table} and/or additional -arguments to be passed on.} - -\item{x}{any \code{R} object or a \link{dict.table} object.} - -\item{copy}{if \code{TRUE} creates a copy of the \link{data.table} object otherwise -works on the passed object by reference.} -} -\description{ -The \link{dict.table} is a combination of \link{dict} and -\href{https://CRAN.R-project.org/package=data.table}{data.table} -and basically can be considered a -\href{https://CRAN.R-project.org/package=data.table}{data.table} -with unique -column names and an extended set of functions to add, extract and -remove data columns with the goal to further facilitate code development -using \href{https://CRAN.R-project.org/package=data.table}{data.table}. -A \link{dict.table} object provides all \link{dict} and -\href{https://CRAN.R-project.org/package=data.table}{data.table} -functions and operators at the same time. -} -\details{ -Methods that alter \link{dict.table} objects usually come in two versions -providing either copy or reference semantics where the latter start with -\code{'ref_'} to note the reference semantic, for example, \code{\link[=add]{add()}} and \code{\link[=ref_add]{ref_add()}}. - -\itemize{ -\item \code{dict.table(...)} initializes and returns a \link{dict} object. -} - -\itemize{ -\item \code{as.dict.table(x, ...)} coerce \code{x} to a \link{dict.table} -} - -\itemize{ -\item \code{is.dict.table(x)} check if \code{x} is a \code{dict.table} -} - -\itemize{ -\item \code{add(.x, ...)} and \code{ref_add(.x, ...)} add columns to \code{.x}. If the column name -already exists, an error is given. -} - -\itemize{ -\item \code{at(.x, ...)} returns the columns at the given indices. Indices -can be letters or numbers or both. All columns must exist. -} - -\itemize{ -\item \code{at2(x, index)} returns the column at the given \code{index} or signals -an error if not found. -} - -\itemize{ -\item \code{clear(x)} and \code{ref_clear(x)} remove all elements from \code{x}. -} - -\itemize{ -\item \code{clone(x)} create a copy of \code{x}. -} - -\itemize{ -\item \code{delete_at(.x, ...)} and \code{ref_delete_at(.x, ...)} find and remove columns either by -name or index (or both). If one or more columns don't exist, an error is signaled. -} - -\itemize{ -\item \code{discard_at(.x, ...)} and \code{ref_discard_at(.x, ...)} find and remove columns -either by name or index (or both). Invalid column indices are ignored. -} - -\itemize{ -\item \code{has(x, column)} check if some \code{column} is in dict.table object. -} - -\itemize{ -\item \code{has_name(x, name)} check if \code{x} has the given column name. -} - -\itemize{ -\item \code{is_empty(x)} \code{TRUE} if object is empty otherwise \code{FALSE} -} - -\itemize{ -\item \code{peek_at(x, ..., .default = NULL)} returns the columns at the given -indices or (if not found) columns with the given default value. -} - -\itemize{ -\item \code{peek_at2(x, index, default = NULL)} return column named \code{index} if it exist -otherwise the given \code{default} value. If the default length does not match -the number of rows, it is recycled accordingly and a warning is given, -unless the default value has a length of 1, in which case recycling is -done silently. -} - -\itemize{ -\item \code{ref_pop(.x, index)} return element at given column index and remove the -column from the dict.table object. -} - -\itemize{ -\item \code{rename(.x, old, new)} and \code{ref_rename(.x, old, new)} rename one or more -columns from \code{old} to \code{new}, respectively, by copy and in place (i.e. by -reference). -} - -\itemize{ -\item \code{replace_at(.x, .., .add = FALSE)} and \code{ref_replace_at(.x, ..., .add = FALSE)} -replace values at given indices. If a given index is invalid, an error is -signaled unless \code{.add} was set to \code{TRUE}. -} - -\itemize{ -\item \code{update(object, other)} and \code{ref_update(object, other)} adds columns of \code{other} dict -that are not yet in \code{object} and replaces the values at existing columns. -} -} -\examples{ -# Some basic examples using some typical data.table and dict operations. -# The constructor can take the 'key' argument known from data.table(): -require(data.table) -dit = dict.table(x = rep(c("b","a","c"), each = 3), y = c(1,3,6), key = "y") -print(dit) -setkey(dit, "x") # sort by 'x' -print(dit) -(add(dit, "v" = 1:9)) # add column v = 1:9 -dit[y > 5] -(ref_discard_at(dit, "x")) # discard column 'x' - -try(at(dit, "x")) # index 'x' not found -try(replace_at(dit, x = 0)) # cannot be replaced, if it does not exist - -dit = replace_at(dit, x = 0, .add = TRUE) # ok - re-adds column 'x' with all 0s -peek_at(dit, "x") # glance at column 'x' -has_name(dit, "x") # TRUE -ref_pop(dit, "x") # get column and remove it -has_name(dit, "x") # FALSE - - -# Copy and reference semantics when coercing *from* a data.table -dat = data.table(a = 1, b = 2) -dit = as.dict.table(dat) -is.dict.table(dit) # TRUE -is.dict.table(dat) # FALSE -ref_replace_at(dit, "a", 9) -dit[["a"]] # 9 -dat[["a"]] # 1 -dit.dat = as.dict.table(dat, copy = FALSE) # init by reference -ref_replace_at(dit.dat, "a", 9) -dat[["a"]] # 9 -is.dict.table(dit.dat) # TRUE -is.dict.table(dat) # TRUE now as well! - -# Coerce from dict -d = dict(a = 1, b = 1:3) -as.dict.table(d) - -dit = dict.table(a = 1:2, b = 1:2) -rbind(dit, dit) - -# rbind ... -dit = dict.table(a = 1:2, b = 1:2) -rbind(dit, dit) - -# ... can be mixed with data.tables -dat = data.table(a = 3:4, b = 3:4) -rbind(dit, dat) # yields a dict.table -rbind(dat, dit) # yields a data.table - -# cbind ... -dit = dict.table(a = 1:2, b = 1:2) -dit2 = dict.table(c = 3:4, d = 5:6) -cbind(dit, dit2) - -# ... can be mixed with data.tables -dat = data.table(x = 3:4, y = 3:4) -cbind(dit, dat) - -dit = dict.table(a = 1:3) -add(dit, b = 3:1, d = 4:6) - -try(add(dit, a = 7:9)) # column 'a' already exists - -dit = dict.table(a = 1:3, b = 4:6) -at(dit, "a") -at(dit, 2) -at(dit, "a", 2) -try(at(dit, "x")) # index 'x' not found -try(at(dit, 1:3)) # index 3 exceeds length of dict.table - -dit = dict.table(a = 1:3, b = 4:6) -at2(dit, 1) -at2(dit, "a") -at2(dit, 2) -try(at2(dit, "x")) # index 'x' not found -try(at2(dit, 5)) # index 5 exceeds length of dict.table - -dit = dict.table(a = 1, b = 2) -clear(dit) -dit -ref_clear(dit) -dit - -d = dict.table(a = 1:2, b = 3:4) -d2 = clone(d) -ref_clear(d) -print(d2) - -(dit = as.dict.table(head(sleep))) -delete_at(dit, "ID") -delete_at(dit, "ID", 1) - -try({ -delete_at(dit, "foo") # Column 'foo' not in dict.table -}) - -dit = as.dict.table(head(sleep)) -discard_at(dit, "ID") -discard_at(dit, "ID", 1) -discard_at(dit, "foo") # ignored - -dit = dict.table(a = 1:3, b = as.list(4:6)) -has(dit, 1:3) # TRUE -has(dit, 4:6) # FALSE -has(dit, as.list(4:6)) # TRUE - -dit = dict.table(a = 1, b = 2) -has_name(dit, "a") # TRUE -has_name(dit, "x") # FALSE - -d = dict.table(a = 1:4, b = 4:1) -is_empty(d) -is_empty(clear(d)) - -dit = dict.table(a = 1:3, b = 4:6) -peek_at(dit, "a") -peek_at(dit, 1) -peek_at(dit, 3) -peek_at(dit, "x") -peek_at(dit, "x", .default = 0) -peek_at(dit, "a", "x", .default = 0) - -dit = dict.table(a = 1:3, b = 4:6) -peek_at2(dit, "a") -peek_at2(dit, 1) -peek_at2(dit, 3) -peek_at2(dit, 3, default = 9) -peek_at2(dit, "x") -peek_at2(dit, "x", default = 0) - -dit = dict.table(a = 1:3, b = 4:6) -ref_pop(dit, "a") -ref_pop(dit, 1) - -try({ -ref_pop(dit, "x") # index 'x' not found -}) - -dit = dict.table(a = 1, b = 2, c = 3) -rename(dit, c("a", "b"), c("a1", "y")) -print(dit) -ref_rename(dit, c("a", "b"), c("a1", "y")) -print(dit) - -dit = dict.table(a = 1:3) -replace_at(dit, "a", 3:1) - -try({ -replace_at(dit, "b", 4:6) # column 'b' not in dict.table -}) -replace_at(dit, "b", 4:6, .add = TRUE) # ok, adds column - -# Update parts of tables (second overwrites columns of the first) -dit1 = dict.table(a = 1:2, b = 3:4) -dit2 = dict.table( b = 5:6, c = 8:9) -update(dit1, dit2) -update(dit2, dit1) -} -\seealso{ -\link{dict}, \href{https://CRAN.R-project.org/package=data.table}{data.table} -} diff --git a/discard.Rd b/discard.Rd deleted file mode 100644 index 87965851..00000000 --- a/discard.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/discard.R -\name{discard} -\alias{discard} -\alias{ref_discard} -\alias{discard.Container} -\alias{ref_discard.Container} -\title{Discard Container Elements} -\usage{ -discard(.x, ...) - -ref_discard(.x, ...) - -\method{discard}{Container}(.x, ...) - -\method{ref_discard}{Container}(.x, ...) -} -\arguments{ -\item{.x}{any \code{R} object.} - -\item{...}{elements to be discarded.} -} -\value{ -For \code{Container}, an object of class \code{Container} (or one of the -respective derived classes). -} -\description{ -Search and remove an element from an object. If the element is not found, -ignore the attempt. -} -\examples{ - -s = setnew("a", num = 1:3, data = iris) -print(s) -discard(s, 1:3, "a") -discard(s, iris) -discard(s, "b") # ignored -} diff --git a/discard_at.Rd b/discard_at.Rd deleted file mode 100644 index 36ef3db4..00000000 --- a/discard_at.Rd +++ /dev/null @@ -1,51 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/discard_at.R -\name{discard_at} -\alias{discard_at} -\alias{ref_discard_at} -\alias{discard_at.Container} -\alias{ref_discard_at.Container} -\alias{discard_at.dict.table} -\alias{ref_discard_at.dict.table} -\title{Discard Elements at Indices} -\usage{ -discard_at(.x, ...) - -ref_discard_at(.x, ...) - -\method{discard_at}{Container}(.x, ...) - -\method{ref_discard_at}{Container}(.x, ...) - -\method{discard_at}{dict.table}(.x, ...) - -\method{ref_discard_at}{dict.table}(.x, ...) -} -\arguments{ -\item{.x}{any \code{R} object.} - -\item{...}{indices at which values are to be discarded.} -} -\value{ -For \code{Container}, an object of class \code{Container} (or one of the -respective derived classes). - -For \code{dict.table}, an object of class \code{dict.table}. -} -\description{ -Search and remove values at given indices, which can be numeric or character -or both. Invalid indices are ignored. -} -\examples{ - -co = container(a = 1, b = 2, 3) -discard_at(co, "a", "b") # [3] -discard_at(co, 1:2) # [3] -discard_at(co, "a", 3) # [b = 2] -discard_at(co, "x") # ignored - -dit = as.dict.table(head(sleep)) -discard_at(dit, "ID") -discard_at(dit, "ID", 1) -discard_at(dit, "foo") # ignored -} diff --git a/docs/404.html b/docs/404.html index f1b567c2..35f5881d 100644 --- a/docs/404.html +++ b/docs/404.html @@ -1,74 +1,34 @@ - - - - + + + + - Page not found (404) • container - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - - -
-
- + +
+ + + - - -
+
+
-
+ + - - diff --git a/docs/articles/code-development.html b/docs/articles/code-development.html index 14af1a44..cd4a3925 100644 --- a/docs/articles/code-development.html +++ b/docs/articles/code-development.html @@ -27,6 +27,8 @@ + +
+
-
-

-Container operations

+
+

Container operations +

Since R has always been used as an interactive tool, base R list operations are generous with respect to errors, which can lead to undetected bugs when developing code. In contrast, the container package provides additional functions for all basic operations that allow for fine control to avoid many pitfalls that can happen with lists and will usually result in more robust code.

-
-

-Add elements

+
+

Add elements +

New elements can be added “as usual” by concatenation or name.

-co <- container()
-co[["x"]] <- 1
-co <- c(co, 2)
-co
-# [x = 1, 2]
+co <- container() +co[["x"]] <- 1 +co <- c(co, 2) +co +# [x = 1, 2]

In addition, the container package provides add, which allows to add new elements by name even if that name exists already.

-co = add(co, x = 3)  # same as c(co, container(x = 3))
-co
-# [x = 1, 2, x = 3]
+co = add(co, x = 3) # same as c(co, container(x = 3)) +co +# [x = 1, 2, x = 3]
-
-

-Replace elements

+
+

Replace elements +

Basic replacement again can be done “as usual” by name or position.

-co[["x"]] <- 0
-co[[2]] <- 12
-co
-# [x = 0, 12, x = 3]
+co[["x"]] <- 0 +co[[2]] <- 12 +co +# [x = 0, 12, x = 3]

In contrast to base lists, the container will not allow to add elements at positions longer than the length of the object.

-co[[4]] <- 4
-# Error: index out of range (length = 3): 4
+co[[4]] <- 4 +# Error: index out of range (length = 3): 4

If the name does not exist, the element is appended as known from base lists.

-co[["y"]] <- 4
-co
-# [x = 0, 12, x = 3, y = 4]
+co[["y"]] <- 4 +co +# [x = 0, 12, x = 3, y = 4]

If you want to make sure that something is replaced, container provides the function replace_at, which will only replace elements if at names or positions that exist. The following statements are all equal and show the different possibilities on how to use replace_at.

-replace_at(co, x = 10, y = 13)            # name = value pairs
-# [x = 10, 12, x = 3, y = 13]
-replace_at(co, c("x", "y"),  c(10, 13))   # names followed by values
-# [x = 10, 12, x = 3, y = 13]
-replace_at(co, c(1, 4),      c(10, 13))   # positions followed by values
-# [x = 10, 12, x = 3, y = 13]
-replace_at(co, list(1, "y"), c(10, 13))   # mixed names/positions followed by values
-# [x = 10, 12, x = 3, y = 13]
+replace_at(co, x = 10, y = 13) # name = value pairs +# [x = 10, 12, x = 3, y = 13] +replace_at(co, c("x", "y"), c(10, 13)) # names followed by values +# [x = 10, 12, x = 3, y = 13] +replace_at(co, c(1, 4), c(10, 13)) # positions followed by values +# [x = 10, 12, x = 3, y = 13] +replace_at(co, list(1, "y"), c(10, 13)) # mixed names/positions followed by values +# [x = 10, 12, x = 3, y = 13]

Now see how invalid indices are signaled.

-replace_at(co, z = 10)
-# Error: names(s) not found: 'z'
-replace_at(co, "z", 10)
-# Error: names(s) not found: 'z'
-replace_at(co, 5, 10)
-# Error: index out of range (length = 4): 5
+replace_at(co, z = 10) +# Error: names(s) not found: 'z' +replace_at(co, "z", 10) +# Error: names(s) not found: 'z' +replace_at(co, 5, 10) +# Error: index out of range (length = 4): 5

If you instead want elements at new names to be added, set .add = TRUE. Invalid positional indices are still signaled.

-co = replace_at(co, z = 10, .add = TRUE)
-co = replace_at(co, 7, 10, .add = TRUE)
-# Error: index out of range (length = 5): 7
-co
-# [x = 0, 12, x = 3, y = 4, z = 10]
+co = replace_at(co, z = 10, .add = TRUE) +co = replace_at(co, 7, 10, .add = TRUE) +# Error: index out of range (length = 5): 7 +co +# [x = 0, 12, x = 3, y = 4, z = 10]

It is also possible to replace elements by value, that is, you specify the value (not the index) that should be replaced. Let’s replace the 12 by “foo” and then 4 by 1:4.

-co = replace(co, 12, "foo")
-co
-# [x = 0, "foo", x = 3, y = 4, z = 10]
-co = replace(co, 4, 1:4)
-co
-# [x = 0, "foo", x = 3, y = (1L 2L 3L 4L), z = 10]
+co = replace(co, 12, "foo") +co +# [x = 0, "foo", x = 3, y = 4, z = 10] +co = replace(co, 4, 1:4) +co +# [x = 0, "foo", x = 3, y = (1L 2L 3L 4L), z = 10]

In an interactive R session you may want to apply the notation using curly braces.

-co[[{1:4}]] <- 1:2
-co
-# [x = 0, "foo", x = 3, y = (1L 2L), z = 10]
+co[[{1:4}]] <- 1:2 +co +# [x = 0, "foo", x = 3, y = (1L 2L), z = 10] -
-

-Extract elements

+
+

Extract elements +

First of all, standard extract operators apply as expected.

-co[[1]]
-# [1] 0
-co[["x"]]
-# [1] 0
-co[3:5]
-# [x = 3, y = (1L 2L), z = 10]
-co[c("x", "y", "z")]
-# [x = 0, y = (1L 2L), z = 10]
+co[[1]] +# [1] 0 +co[["x"]] +# [1] 0 +co[3:5] +# [x = 3, y = (1L 2L), z = 10] +co[c("x", "y", "z")] +# [x = 0, y = (1L 2L), z = 10]

Programmatically, the corresponding functions to select one or multiple elements are named at2 and at.

-at2(co, 1)
-# [1] 0
-at2(co, "x")
-# [1] 0
-at(co, 3:5)
-# [x = 3, y = (1L 2L), z = 10]
-at(co, c("x", "y", "z"))
-# [x = 0, y = (1L 2L), z = 10]
+at2(co, 1) +# [1] 0 +at2(co, "x") +# [1] 0 +at(co, 3:5) +# [x = 3, y = (1L 2L), z = 10] +at(co, c("x", "y", "z")) +# [x = 0, y = (1L 2L), z = 10]

As before you can specify mixed indices via lists.

-indices = list("x", 4, "z")
-at(co, indices)
-# [x = 0, y = (1L 2L), z = 10]
+indices = list("x", 4, "z") +at(co, indices) +# [x = 0, y = (1L 2L), z = 10]

Again, accessing non-existent names or positions is signaled with an error.

-at2(co, 10)
-# Error: index 10 exceeds length of Container, which is 5
-at2(co, "a")
-# Error: index 'a' not found
-at(co, 3:6)
-# Error: index 6 exceeds length of Container, which is 5
-at(co, c("x", "a"))
-# Error: index 'a' not found
+at2(co, 10) +# Error: index 10 exceeds length of Container, which is 5 +at2(co, "a") +# Error: index 'a' not found +at(co, 3:6) +# Error: index 6 exceeds length of Container, which is 5 +at(co, c("x", "a")) +# Error: index 'a' not found

With base R lists non-existent indices usually yield NULL.

-l = list()
-l[["a"]]
-# NULL
-l[2:3]
-# [[1]]
-# NULL
-# 
-# [[2]]
-# NULL
+l = list() +l[["a"]] +# NULL +l[2:3] +# [[1]] +# NULL +# +# [[2]] +# NULL

If needed, the (less strict) list access can be mimicked with peek_at and peek_at2.

-peek_at2(co, "a")
-# NULL
-peek_at(co, 10, 11)
-# []
-peek_at(co, 5:10)
-# [z = 10]
+peek_at2(co, "a") +# NULL +peek_at(co, 10, 11) +# [] +peek_at(co, 5:10) +# [z = 10]

As you see, one important difference is multiple access via peek_at will not insert NULL values by default. However, both functions in fact allow to specify the default value that is returned if the index does not exist.

-peek_at2(co, "a", default = -1)
-# [1] -1
-
-peek_at(co, "z", "a", .default = -1)
-# [z = 10, a = -1]
-peek_at(co, 4:8, .default = NA)
-# [y = (1L 2L), z = 10, NA, NA, NA]
+peek_at2(co, "a", default = -1) +# [1] -1 + +peek_at(co, "z", "a", .default = -1) +# [z = 10, a = -1] +peek_at(co, 4:8, .default = NA) +# [y = (1L 2L), z = 10, NA, NA, NA] -
-

-Remove elements

+
+

Remove elements +

To remove elements in lists, they have to be replaced by NULL.

-l = list(a = 1)
-l
-# $a
-# [1] 1
-l[["a"]] <- NULL
-l
-# named list()
+l = list(a = 1) +l +# $a +# [1] 1 +l[["a"]] <- NULL +l +# named list()

With the container package this is done differently, as replacing by NULL will not delete the element but literally replace it by NULL.

-co[["x"]] <- NULL
-co
-# [x = NULL, "foo", x = 3, y = (1L 2L), z = 10]
+co[["x"]] <- NULL +co +# [x = NULL, "foo", x = 3, y = (1L 2L), z = 10]

Instead, elements can be deleted by index (delete_at) or value (delete) as follows.

-delete_at(co, 1, "y", "z")
-# ["foo", x = 3]
-delete(co, NULL, 1:2, 10)   # same but remove by value
-# ["foo", x = 3]
+delete_at(co, 1, "y", "z") +# ["foo", x = 3] +delete(co, NULL, 1:2, 10) # same but remove by value +# ["foo", x = 3]

As before, invalid indices or missing values are signaled.

-delete_at(co, "a")
-# Error: names(s) not found: 'a'
-delete_at(co, 10)
-# Error: index out of range (length = 5): 10
-
-delete(co, 1:3)
-# Error: (1L 2L 3L) is not in Container
+delete_at(co, "a") +# Error: names(s) not found: 'a' +delete_at(co, 10) +# Error: index out of range (length = 5): 10 + +delete(co, 1:3) +# Error: (1L 2L 3L) is not in Container

If you need a less strict delete operation, use the discard functions, which delete all valid indices/values and ignore the rest.

-discard_at(co, 1, "a")
-# ["foo", x = 3, y = (1L 2L), z = 10]
-discard_at(co, 1:100)
-# []
-
-discard(co, NULL, 1:2, 1:3, 1:4)
-# ["foo", x = 3, z = 10]
+discard_at(co, 1, "a") +# ["foo", x = 3, y = (1L 2L), z = 10] +discard_at(co, 1:100) +# [] + +discard(co, NULL, 1:2, 1:3, 1:4) +# ["foo", x = 3, z = 10] -
-

-Combine containers

+
+

Combine containers +

The update function is used to combine/merge two containers.

-c1 = container(1, b = 2)
-c2 = container(   b = 0, c = 3)
-
-update(c1, c2)
-# [1, b = 0, c = 3]
-update(c2, c1)
-# [b = 2, c = 3, 1]
+c1 = container(1, b = 2) +c2 = container( b = 0, c = 3) + +update(c1, c2) +# [1, b = 0, c = 3] +update(c2, c1) +# [b = 2, c = 3, 1]

With the container package this function is also provided for base R lists.

-l1 = list(1, b = 2)
-l2 = list(   b = 0, c = 3)
-
-update(l1, l2)
-# [[1]]
-# [1] 1
-# 
-# $b
-# [1] 0
-# 
-# $c
-# [1] 3
-update(l2, l1)
-# $b
-# [1] 2
-# 
-# $c
-# [1] 3
-# 
-# [[3]]
-# [1] 1
+l1 = list(1, b = 2) +l2 = list( b = 0, c = 3) + +update(l1, l2) +# [[1]] +# [1] 1 +# +# $b +# [1] 0 +# +# $c +# [1] 3 +update(l2, l1) +# $b +# [1] 2 +# +# $c +# [1] 3 +# +# [[3]] +# [1] 1
@@ -397,11 +401,13 @@

@@ -410,5 +416,7 @@

+ + diff --git a/docs/articles/container.html b/docs/articles/container.html index 1fe7f933..d26a0157 100644 --- a/docs/articles/container.html +++ b/docs/articles/container.html @@ -27,6 +27,8 @@ + +
+
-
-

-When not to use container

-

Don’t bother using the container framework if speed is of high importance. An exception is the dict.table class, which is very fast as it is based on data.table. Other than that, if computation speed is critical for your application, we refer you to using base R list or packages that were optimized for performance, such as the collections package.

+
+

When not to use container +

+

Don’t bother using the container framework if speed is of high importance. An exception is the dict.table class, which is very fast as it is based on data.table. Other than that, if computation speed is critical for your application, we refer you to using base R list or packages that were optimized for performance, such as the collections package.

-
-

-When to use container

+
+

When to use container +

Consider using the container framework over base list if you are looking for …

Furthermore consider using dict.table for a flexible and robust way to manage data columns of data.tables.

-
-

-container in interactive R session

+
+

container in interactive R session +

In an interactive R session a container can be used similar to a base R list, but also provides some extra features. For easier typing it’s recommended to use the shorter cont.

-library(container)
-co = cont(a = 1, b = 1:10)  # same as co = container(a = 1, b = 1:10)
+library(container) +co = cont(a = 1, b = 1:10) # same as co = container(a = 1, b = 1:10)

The container print method is designed to be very compact.

-print(co)
-# [a = 1, b = (1L 2L 3L 4L ...)]
+print(co) +# [a = 1, b = (1L 2L 3L 4L ...)]

For more verbose output, either convert to a base list

-as.list(co)
-# $a
-# [1] 1
-# 
-# $b
-#  [1]  1  2  3  4  5  6  7  8  9 10
+as.list(co) +# $a +# [1] 1 +# +# $b +# [1] 1 2 3 4 5 6 7 8 9 10

or use str.

-str(co)
-# Container of 2 
-#  $ a: num 1
-#  $ b: int [1:10] 1 2 3 4 5 6 7 8 9 10
+str(co) +# Container of 2 +# $ a: num 1 +# $ b: int [1:10] 1 2 3 4 5 6 7 8 9 10

Both length and names work as usual.

-length(co)
-# [1] 2
-
-names(co)
-# [1] "a" "b"
-
-names(co)[1] <- "A"
-co
-# [A = 1, b = (1L 2L 3L 4L ...)]
+length(co) +# [1] 2 + +names(co) +# [1] "a" "b" + +names(co)[1] <- "A" +co +# [A = 1, b = (1L 2L 3L 4L ...)]

A container can also be constructed from a list.

-l = list(x = (1:2)^1, y = (1:2)^2)
-co2 = as.container(l)
-co2
-# [x = (1 2), y = (1 4)]
-
-

-Add elements

+l = list(x = (1:2)^1, y = (1:2)^2) +co2 = as.container(l) +co2 +# [x = (1 2), y = (1 4)]
+
+

Add elements +

Elements can be added by concatenation,

-c(co, co2)
-# [A = 1, b = (1L 2L 3L 4L ...), x = (1 2), y = (1 4)]
+c(co, co2) +# [A = 1, b = (1L 2L 3L 4L ...), x = (1 2), y = (1 4)]

or name,

-co[["c"]] <- 3
-co
-# [A = 1, b = (1L 2L 3L 4L ...), c = 3]
+co[["c"]] <- 3 +co +# [A = 1, b = (1L 2L 3L 4L ...), c = 3]

and containers can be nested.

-co[["co2"]] <- co2
-co
-# [A = 1, b = (1L 2L 3L 4L ...), c = 3, co2 = [x = (1 2), y = (1 4)]]
+co[["co2"]] <- co2 +co +# [A = 1, b = (1L 2L 3L 4L ...), c = 3, co2 = [x = (1 2), y = (1 4)]]

In contrast to base R list, elements cannot be added via positional index if it exceeds the container’s length.

-co[[5]] <- 5
-# Error: index out of range (length = 4): 5
+co[[5]] <- 5 +# Error: index out of range (length = 4): 5
-
-

-Replace values

+
+

Replace values +

Single or multiple value replacement works as usual.

-co[[3]] <- 0
-co[1:2] <- 0
-co
-# [A = 0, b = 0, c = 0, co2 = [x = (1 2), y = (1 4)]]
+co[[3]] <- 0 +co[1:2] <- 0 +co +# [A = 0, b = 0, c = 0, co2 = [x = (1 2), y = (1 4)]]

In contrast to base list, containers can take a mix of numeric and character indices.

-co[list("A", 2, "c")] <- list(1, 2, "three")
-co
-# [A = 1, b = 2, c = "three", co2 = [x = (1 2), y = (1 4)]]
+co[list("A", 2, "c")] <- list(1, 2, "three") +co +# [A = 1, b = 2, c = "three", co2 = [x = (1 2), y = (1 4)]]

Another option for container object is to replace by value.

-co[[{"three"}]] <- 3
-co
-# [A = 1, b = 2, c = 3, co2 = [x = (1 2), y = (1 4)]]
+co[[{"three"}]] <- 3 +co +# [A = 1, b = 2, c = 3, co2 = [x = (1 2), y = (1 4)]]

This works for any data type.

-co[[{co2}]] <- 3
-co
-# [A = 1, b = 2, c = 3, co2 = 3]
+co[[{co2}]] <- 3 +co +# [A = 1, b = 2, c = 3, co2 = 3] -
-

-Extract

+
+

Extract +

The standard operators to access elements also should be familiar to R users. 1

-co[[1]]
-# [1] 1
-co[1:3]
-# [A = 1, b = 2, c = 3]
+co[[1]] +# [1] 1 +co[1:3] +# [A = 1, b = 2, c = 3]

As another option, you can pass any number of indices, possibly mixed as numeric and character.

-co[1, 3, "b"]
-# [A = 1, c = 3, b = 2]
-
-co[2:1, "A"]
-# [b = 2, A = 1, A = 1]
+co[1, 3, "b"] +# [A = 1, c = 3, b = 2] + +co[2:1, "A"] +# [b = 2, A = 1, A = 1]

Invalid indices don’t produce NULLs but are just ignored.

-co[1:100]
-# [A = 1, b = 2, c = 3, co2 = 3]
+co[1:100] +# [A = 1, b = 2, c = 3, co2 = 3] -
-

-Inspect

+
+

Inspect +

Count the number of elements.

-count(co, 1)
-# [1] 1
-count(co, 3)
-# [1] 2
+count(co, 1) +# [1] 1 +count(co, 3) +# [1] 2

Use the apply family.

-sapply(co, is.numeric)
-#    A    b    c  co2 
-# TRUE TRUE TRUE TRUE
-
-sapply(co, function(x) x + 1)
-#   A   b   c co2 
-#   2   3   4   4
+sapply(co, is.numeric) +# A b c co2 +# TRUE TRUE TRUE TRUE + +sapply(co, function(x) x + 1) +# A b c co2 +# 2 3 4 4
-
-

-container in code development

+
+

container in code development +

Next, see vignette Container operations for robust code.


    -
  1. Note that the $ operator does not work.↩︎

  2. +
  3. Note that the $ operator does not work.↩︎

@@ -332,11 +336,13 @@

@@ -345,5 +351,7 @@

+ + diff --git a/docs/articles/deque-set-dict.html b/docs/articles/deque-set-dict.html index cb99a12c..9f45808f 100644 --- a/docs/articles/deque-set-dict.html +++ b/docs/articles/deque-set-dict.html @@ -27,6 +27,8 @@ + +
+
@@ -162,134 +166,134 @@

Deque, Set, and Dict

The container package provides specialized data structures that technically are all derived from the Container class. As such they share all of the container functions with some of them being overridden to account for the specialized data structure. In particular, all of the derived structures still provide positional element access to still behave similar to base R lists.

-
-

-Deque

+
+

Deque +

Deques (double ended queues) are a generalization of stacks and queues and therefore also can be used to mimic these.

-
-

-Stack

+
+

Stack +

A stack is a last-in-first-out (LIFO) data structure with two basic operations, push and pop, which in this case are mimicked with ref_add and ref_pop.

-# Mimic stack
-s = deque()
-s
-# ||
-ref_add(s, 1)
-ref_add(s, 2)
-s
-# |1, 2|
-
-ref_pop(s)
-# [1] 2
-ref_pop(s)
-# [1] 1
-s
-# ||
+# Mimic stack +s = deque() +s +# || +ref_add(s, 1) +ref_add(s, 2) +s +# |1, 2| + +ref_pop(s) +# [1] 2 +ref_pop(s) +# [1] 1 +s +# ||
-
-

-Queues

+
+

Queues +

A queue is a first-in-first-out (FIFO) data structure with two basic operations, push and pop_left (or enqueue and dequeue), which in this case are mimicked with ref_add and ref_popleft.

-# Mimic queue
-q = deque()
-q
-# ||
-ref_add(q, 1)
-ref_add(q, 2)
-q
-# |1, 2|
-
-ref_popleft(q)
-# [1] 1
-ref_popleft(q)
-# [1] 2
-q
-# ||
+# Mimic queue +q = deque() +q +# || +ref_add(q, 1) +ref_add(q, 2) +q +# |1, 2| + +ref_popleft(q) +# [1] 1 +ref_popleft(q) +# [1] 2 +q +# ||

A double-ended queue works on both ends and also provides rotate and reverse operations.

-d = as.deque(1:4)
-d
-# |1L, 2L, 3L, 4L|
-rev(d)
-# |4L, 3L, 2L, 1L|
-rotate(d, 2)
-# |3L, 4L, 1L, 2L|
+d = as.deque(1:4) +d +# |1L, 2L, 3L, 4L| +rev(d) +# |4L, 3L, 2L, 1L| +rotate(d, 2) +# |3L, 4L, 1L, 2L|
-
-

-Set

+
+

Set +

All elements of a set are unique. Basic set operations are provided.

-s1 = setnew(1, "1", 2, cars)
-s2 = setnew(1,      2, 3, iris)
-
-s1 & s2
-# {1, 2}
-s1 | s2
-# {1, "1", 2, <<data.frame(50x2)>>, 3, <<data.frame(150x5)>>}
-s1 - s2
-# {"1", <<data.frame(50x2)>>}
+s1 = setnew(1, "1", 2, cars) +s2 = setnew(1, 2, 3, iris) + +s1 & s2 +# {1, 2} +s1 | s2 +# {1, "1", 2, <<data.frame(50x2)>>, 3, <<data.frame(150x5)>>} +s1 - s2 +# {"1", <<data.frame(50x2)>>}

It is important to note that set comparison for the standard set is not order-invariant, e.g.:

-s1 = setnew(1, 2, 3)
-s2 = setnew(2, 1, 3)
-s1 == s2
-# [1] FALSE
+s1 = setnew(1, 2, 3) +s2 = setnew(2, 1, 3) +s1 == s2 +# [1] FALSE

This property is intended to allow positional access also in sets (remember that technically the ‘Set’ class is derived from ‘Container’).

-s1[1:2]
-# {1, 2}
-s2[1:2]
-# {2, 1}
+s1[1:2] +# {1, 2} +s2[1:2] +# {2, 1}

If you want order-invariant sets, just use the OrderedSet.

-os1 = as.orderedset(s1)
-os2 = as.orderedset(s2)
-os1
-# {1, 2, 3}
-os2
-# {1, 2, 3}
-os1 == os2
-# [1] TRUE
-

Last but not least, the container package only covers a small range of sets and set functions. For a wide range of set functionality and data structures such as fuzzy sets, multisets, customizable sets and intervals, please refer to the sets package by David Meyer.

+os1 = as.orderedset(s1) +os2 = as.orderedset(s2) +os1 +# {1, 2, 3} +os2 +# {1, 2, 3} +os1 == os2 +# [1] TRUE
+

Last but not least, the container package only covers a small range of sets and set functions. For a wide range of set functionality and data structures such as fuzzy sets, multisets, customizable sets and intervals, please refer to the sets package by David Meyer.

-
-

-Dict

+
+

Dict +

In a dictionary, each element is mapped to a name. In the container package, dicts are always sorted by name, either after initialization …

-d = dict(z = 2, a = 10)
-d
-# {a = 10, z = 2}
+d = dict(z = 2, a = 10) +d +# {a = 10, z = 2}

… or when new elements are added.

-d[["x"]] = 1
-d
-# {a = 10, x = 1, z = 2}
+d[["x"]] = 1 +d +# {a = 10, x = 1, z = 2}

If added using the add function, a name clash is signaled to prevent overwriting existing elements.

-add(d, z = 3)
-# Error: name 'z' exists already
+add(d, z = 3) +# Error: name 'z' exists already

To overwrite, you can use one of three approaches.

-d[["z"]] = 3
-replace_at(d, z = 3)
-# {a = 10, x = 1, z = 3}
-update(d, dict(z = 3))
-# {a = 10, x = 1, z = 3}
+d[["z"]] = 3 +replace_at(d, z = 3) +# {a = 10, x = 1, z = 3} +update(d, dict(z = 3)) +# {a = 10, x = 1, z = 3}

By design, elements can be accessed by name or position, the latter always based on the ordered elements.

-d["x", "a"]
-# {a = 10, x = 1}
-d[2:1]
-# {a = 10, x = 1}
-
-add(d, b = 3)[2:1]
-# {a = 10, b = 3}
-

For more examples see the vignette Manage parameter lists with dict.

+d["x", "a"] +# {a = 10, x = 1} +d[2:1] +# {a = 10, x = 1} + +add(d, b = 3)[2:1] +# {a = 10, b = 3} +

For more examples see the vignette Manage parameter lists with dict.

@@ -304,11 +308,13 @@

@@ -317,5 +323,7 @@

+ + diff --git a/docs/articles/index.html b/docs/articles/index.html index a6a8ee4e..2ac95841 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -1,74 +1,12 @@ - - - - - - - -Articles • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Articles • container + + - - - - -
-
- -
- -
+
+
Introduction to container
+

Start here if this is your first time using container. This vignette describes when and when not to use container, and gives a brief introduction on basic container operations.

+
Container operations for robust code
+

Use this vignette if you want to see how container operations can be used to make it safer and easier to work with list-like data structures. It describes the different methods to add, extract, replace, and remove elements and their nuances.

+
Manage parameter lists with dict
+

The original motivation for the development of this package was that the author found himself writing countless checks and helper code over and over again when managing parameter lists. This vignette describes how to use the dictionary to manage parameter lists safely and with ease.

+
Manage data columns with dict.table
+

The dict.table as a mix of data.table and Dict extends the data.table by functions to enhance data column management. This vignette compares basic dplyr and dict.table data column operations and shows how both frameworks can be easily combined.

+
Deque, Set, and Dict
+

Presents the specialized data structures Deque, Set, and Dict.

+
Reference semantics
+

Gives a brief overview about the reference semantic functionality provided by the container package.

+
-
- - + + diff --git a/docs/articles/manage-data-columns.html b/docs/articles/manage-data-columns.html index 783aad91..73c17fa0 100644 --- a/docs/articles/manage-data-columns.html +++ b/docs/articles/manage-data-columns.html @@ -18,7 +18,7 @@ - + +
+
-
-

-Motivation

-

The dplyr functions select and mutate are widely used to manage data data.frame (or tibble) columns. They cover a wide range of use cases and are applied in quick data exploration as well as in data analysis pipelines. On the other hand, when implementing critical code or building R packages, developers may revert to base R to minimize errors and code dependencies. At least, both mutate and select may require additional checking, for example, to catch column name clashes.

-

The container package in parts was developed to close this gap. With version 1.0.0, it provides dict.table, which can be considered a data.table with an extended set of functions to add, extract, remove and replace data columns with minimal required additional checking, hopefully resulting in lean and robust code.

+
+

Motivation +

+

The dplyr functions select and mutate are widely used to manage data data.frame (or tibble) columns. They cover a wide range of use cases and are applied in quick data exploration as well as in data analysis pipelines. On the other hand, when implementing critical code or building R packages, developers may revert to base R to minimize errors and code dependencies. At least, both mutate and select may require additional checking, for example, to catch column name clashes.

+

The container package in parts was developed to close this gap. With version 1.0.0, it provides dict.table, which can be considered a data.table with an extended set of functions to add, extract, remove and replace data columns with minimal required additional checking, hopefully resulting in lean and robust code.

This vignette compares basic dplyr and dict.table data column operations and at the end shows that both frameworks can be easily combined.

-
-

-Column operations

+
+

Column operations +

To keep matters simple, we use a tiny data set.

-library(container)
-library(dplyr)
-
-data <- dict.table(x = c(0.2, 0.5), y = letters[1:2])
-data
-# <dict.table> with 2 rows and 2 columns
-#      x y
-# 1: 0.2 a
-# 2: 0.5 b
-
-

-Add

+library(container) +library(dplyr) + +data <- dict.table(x = c(0.2, 0.5), y = letters[1:2]) +data +# <dict.table> with 2 rows and 2 columns +# x y +# 1: 0.2 a +# 2: 0.5 b
+
+

Add +

Let’s add columns using mutate.

-data %>%
-    mutate(ID = 1:2, z = 1)
-# <dict.table> with 2 rows and 4 columns
-#      x y ID z
-# 1: 0.2 a  1 1
-# 2: 0.5 b  2 1
-

For someone not familar with the tidyverse, this code block might read somewhat odd as the column is added and not mutated. To add a column via dict.table use add.

+data %>% + mutate(ID = 1:2, z = 1) +# <dict.table> with 2 rows and 4 columns +# x y ID z +# 1: 0.2 a 1 1 +# 2: 0.5 b 2 1
+

For someone not familar with the tidyverse, this code block might read somewhat odd as the column is added and not mutated. To add a column via dict.table use add.

-data %>%
-    add(ID = 1:2, z = 1)
-# <dict.table> with 2 rows and 4 columns
-#      x y ID z
-# 1: 0.2 a  1 1
-# 2: 0.5 b  2 1
+data %>% + add(ID = 1:2, z = 1) +# <dict.table> with 2 rows and 4 columns +# x y ID z +# 1: 0.2 a 1 1 +# 2: 0.5 b 2 1

The intend to add a column thus is stated more clearly. Next, instead of ID, let’s add another numeric column y, which happens to “name-clash” with the already existing column.

-data %>%
-    mutate(y = 1)
-# <dict.table> with 2 rows and 2 columns
-#      x y
-# 1: 0.2 1
-# 2: 0.5 1
+data %>% + mutate(y = 1) +# <dict.table> with 2 rows and 2 columns +# x y +# 1: 0.2 1 +# 2: 0.5 1

Of course, the initial y-column has been overwritten. While this was easy to see here, it may not if the data has a lot of columns or if column names are created dynamically during runtime. To catch this, usually some overhead is required.

-if ("y" %in% colnames(data)) {
-    stop("column y already exists")
-} else {
-    data %>%
-        mutate(y = 1)
-}
-# Error in eval(expr, envir, enclos): column y already exists
+if ("y" %in% colnames(data)) { + stop("column y already exists") +} else { + data %>% + mutate(y = 1) +} +# Error in eval(expr, envir, enclos): column y already exists

Let’s see the dict.table-operation in comparison.

-data %>%
-    add(y = 1)
-# Error: name 'y' exists already
+data %>% + add(y = 1) +# Error: name 'y' exists already

The name clash is caught by default and therefore requires no additional checking.

-
-

-Modify

+
+

Modify +

If the intend was indeed to overwrite the value, the dict.table function replace_at can be used.

-data %>%
-    replace_at(y = 1)
-# <dict.table> with 2 rows and 2 columns
-#      x y
-# 1: 0.2 1
-# 2: 0.5 1
-
-# or programmatically
-data %>%
-    replace_at("y", 1)
-# <dict.table> with 2 rows and 2 columns
-#      x y
-# 1: 0.2 1
-# 2: 0.5 1
+data %>% + replace_at(y = 1) +# <dict.table> with 2 rows and 2 columns +# x y +# 1: 0.2 1 +# 2: 0.5 1 + +# or programmatically +data %>% + replace_at("y", 1) +# <dict.table> with 2 rows and 2 columns +# x y +# 1: 0.2 1 +# 2: 0.5 1

As we saw above, if a column does not exist, mutate silently creates it for you. If this is not what you want, which means, you want to make sure something is overwritten, again, a workaround is needed.

-if ("ID" %in% colnames(data)) {
-    data %>%
-        mutate(ID = 1:2)
-} else {
-    stop("column ID not in data.frame")
-}
-# Error in eval(expr, envir, enclos): column ID not in data.frame
+if ("ID" %in% colnames(data)) { + data %>% + mutate(ID = 1:2) +} else { + stop("column ID not in data.frame") +} +# Error in eval(expr, envir, enclos): column ID not in data.frame

Once again, the workaround is already “built-in” in the dict.table-framework,

-data %>%
-    replace_at(ID = 1:2)
-# Error: column(s) not found: 'ID'
+data %>% + replace_at(ID = 1:2) +# Error: column(s) not found: 'ID'

that is, replace_at expects the column to exist.

If we were to paraphrase the intend of the mutate function, it probably would be something like “Replace a column or, if it does not exist, add it.”. As you may already have guessed, this can also be expressed within the dict.table-framework.

-data %>%
-    replace_at(ID = 1:2, .add = TRUE)
-# <dict.table> with 2 rows and 3 columns
-#      x y ID
-# 1: 0.2 a  1
-# 2: 0.5 b  2
+data %>% + replace_at(ID = 1:2, .add = TRUE) +# <dict.table> with 2 rows and 3 columns +# x y ID +# 1: 0.2 a 1 +# 2: 0.5 b 2
-
-

-Remove

-

A common tidyverse approach to remove a column is based on the select function. One corresponding dict.table-function is delete.

+
+

Remove +

+

A common tidyverse approach to remove a column is based on the select function. One corresponding dict.table-function is delete.

-data %>%
-  select(-"y")
-# <dict.table> with 2 rows and 1 column
-#      x
-# 1: 0.2
-# 2: 0.5
-
-data %>%
-    delete_at("y")
-# <dict.table> with 2 rows and 1 column
-#      x
-# 1: 0.2
-# 2: 0.5
+data %>% + select(-"y") +# <dict.table> with 2 rows and 1 column +# x +# 1: 0.2 +# 2: 0.5 + +data %>% + delete_at("y") +# <dict.table> with 2 rows and 1 column +# x +# 1: 0.2 +# 2: 0.5

Let’s see what happens if the column does not exist in the first place.

-data %>%
-    select(-"ID")
-# Error: Can't subset columns that don't exist.
-# x Column `ID` doesn't exist.
-
-data %>%
-    delete_at("ID")
-# Error: column(s) not found: 'ID'
+data %>% + select(-"ID") +# Error in `select()`: +# ! Can't subset columns that don't exist. +# x Column `ID` doesn't exist. + +data %>% + delete_at("ID") +# Error: column(s) not found: 'ID'

So in this case, both frameworks will complain. Now assume we want the column to be removed if it exist but otherwise silently ignore the command, for example:

-if ("ID" %in% colnames(data)) {
-    data %>%
-        select(-"ID")
-}
+if ("ID" %in% colnames(data)) { + data %>% + select(-"ID") +}

The dict.table provides a straight-forward solution via the discard function:

-data %>%
-    discard_at("ID")
-# <dict.table> with 2 rows and 2 columns
-#      x y
-# 1: 0.2 a
-# 2: 0.5 b
+data %>% + discard_at("ID") +# <dict.table> with 2 rows and 2 columns +# x y +# 1: 0.2 a +# 2: 0.5 b -
-

-Benchmark

-

To compare the performance of both frameworks, we benchmark some column operations using the standard ‘cars’ data set. As a hallmark reference we use data.table.

+
+

Benchmark +

+

To compare the performance of both frameworks, we benchmark some column operations using the standard ‘cars’ data set. As a hallmark reference we use data.table.

-library(microbenchmark)
-library(ggplot2)
-library(data.table)
-library(tibble)
-
-data = cars
-head(cars)
-#   speed dist
-# 1     4    2
-# 2     4   10
-# 3     7    4
-# 4     7   22
-# 5     8   16
-# 6     9   10
+library(microbenchmark) +library(ggplot2) +library(data.table) +library(tibble) + +data = cars +head(cars) +# speed dist +# 1 4 2 +# 2 4 10 +# 3 7 4 +# 4 7 22 +# 5 8 16 +# 6 9 10

For the benchmark, we add, replace and finally delete a column.

-bm <- microbenchmark(control = list(order="inorder"), times = 100,
-
-    dict.table =
-        as.dict.table(data) %>%
-        add(time = .[["dist"]] / .[["speed"]]) %>%
-        replace_at(dist = 0) %>%
-        delete_at("speed"),
-
-    `data.table[` =
-        as.data.table(data)[
-        ][, time := dist / speed
-        ][, dist := 0
-        ][, speed := NULL],
-
-    dplyr =
-        as_tibble(data) %>%
-        mutate(time = dist / speed) %>%
-        mutate(dist = 0) %>%
-        select(-speed)
-)
-autoplot(bm) + theme_bw()
+bm <- microbenchmark(control = list(order="inorder"), times = 100, + + dict.table = + as.dict.table(data) %>% + add(time = .[["dist"]] / .[["speed"]]) %>% + replace_at(dist = 0) %>% + delete_at("speed"), + + `data.table[` = + as.data.table(data)[ + ][, time := dist / speed + ][, dist := 0 + ][, speed := NULL], + + dplyr = + as_tibble(data) %>% + mutate(time = dist / speed) %>% + mutate(dist = 0) %>% + select(-speed) +) +autoplot(bm) + theme_bw()

While dict.table and data.table performed nearly the same there is some distance to dplyr (about 10x). Let’s examine each operation in more detail.

-data = cars
-bm <- microbenchmark(control = list(order="inorder"), times = 100,
-
-    dit <- as.dict.table(data),
-    dit <- add(dit, time = dit[["dist"]] / dit[["speed"]]),
-    dit <- replace_at(dit, dist = 0),
-    dit <- delete_at(dit, "speed"),
-
-    dat <-  as.data.table(data),
-    dat[, time := dist / speed],
-    dat[, dist := 0],
-    dat[, speed := NULL],
-
-    tbl <- as_tibble(data),
-    tbl <- mutate(tbl, time = dist / speed),
-    tbl <- mutate(tbl, dist = 0),
-    tbl <- select(tbl, -speed)
-)
-autoplot(bm) + theme_bw()
+data = cars +bm <- microbenchmark(control = list(order="inorder"), times = 100, + + dit <- as.dict.table(data), + dit <- add(dit, time = dit[["dist"]] / dit[["speed"]]), + dit <- replace_at(dit, dist = 0), + dit <- delete_at(dit, "speed"), + + dat <- as.data.table(data), + dat[, time := dist / speed], + dat[, dist := 0], + dat[, speed := NULL], + + tbl <- as_tibble(data), + tbl <- mutate(tbl, time = dist / speed), + tbl <- mutate(tbl, dist = 0), + tbl <- select(tbl, -speed) +) +autoplot(bm) + theme_bw()

Apparently, the mutate and select operations are the slowest in comparison, which for the most part should be a result of these functions providing non-standard evaluation (NSE) and generally a wide range of ways to specify the desired operation. Unsurprisingly such flexibility comes at a cost.

-

Since the data.table expressions also involve NSE terms and some overhead, in this benchmark the dict.table performs even best. Having said that, of course, the data.table code can be further improved by avoiding the overhead and instead use reference semantics via the data.table built-in set function.

+

Since the data.table expressions also involve NSE terms and some overhead, in this benchmark the dict.table performs even best. Having said that, of course, the data.table code can be further improved by avoiding the overhead and instead use reference semantics via the data.table built-in set function.

-data = cars
-bm <- microbenchmark(control = list(order="inorder"), times = 100,
-
-    dict.table =
-        as.dict.table(data) %>%
-        add(time = dit[["dist"]] / dit[["speed"]]) %>%
-        replace_at(dist = 0) %>%
-        delete_at("speed"),
-
-    ref_dict.table =
-        as.dict.table(data) %>%
-        ref_add(time = .[["dist"]] / .[["speed"]]) %>%
-        ref_replace_at(dist = 0) %>%
-        ref_delete_at("speed"),
-
-    `data.table[` =
-        as.data.table(data)[
-        ][, time := dist / speed
-        ][, dist := 0
-        ][, speed := NULL],
-
-    set_data.table =
-        as.data.table(data) %>%
-        set(j = "ID", value = .[["dist"]] / .[["speed"]]) %>%
-        set(j = "dist", value = 0) %>%
-        set(j = "speed", value = NULL)
-)
-
-autoplot(bm) + theme_bw()
+data = cars +bm <- microbenchmark(control = list(order="inorder"), times = 100, + + dict.table = + as.dict.table(data) %>% + add(time = dit[["dist"]] / dit[["speed"]]) %>% + replace_at(dist = 0) %>% + delete_at("speed"), + + ref_dict.table = + as.dict.table(data) %>% + ref_add(time = .[["dist"]] / .[["speed"]]) %>% + ref_replace_at(dist = 0) %>% + ref_delete_at("speed"), + + `data.table[` = + as.data.table(data)[ + ][, time := dist / speed + ][, dist := 0 + ][, speed := NULL], + + set_data.table = + as.data.table(data) %>% + set(j = "ID", value = .[["dist"]] / .[["speed"]]) %>% + set(j = "dist", value = 0) %>% + set(j = "speed", value = NULL) +) + +autoplot(bm) + theme_bw()

This puts things back into perspective. We also provided a dict.table version using reference semantic, which is also built-in and results in a slight speed improvement over the standard version. As a result, data.table remains the way to go when speed is key.

-
-

-Combine dplyr and dict.table

+
+

Combine dplyr and dict.table +

Since a dict.table is fully compatible with dplyr and data.table, all of the presented frameworks can be easily combined in any order.

-res = data %>%
-    as.dict.table %>%
-    .[, time := dist / speed] %>%   # data.table
-    replace_at(dist = 0) %>%        # container
-    select(-speed)                  # dplyr
+res = data %>% + as.dict.table %>% + .[, time := dist / speed] %>% # data.table + replace_at(dist = 0) %>% # container + select(-speed) # dplyr
-
-

-Summary

+
+

Summary +

In critical code, it is usually of high priority to avoid unintended data column operations. For this, usually additional code is required to check for the existence or absence of columns. The dict.table framework provides a set of column operations with built-in checking, thereby yielding safer and leaner code out of the box and ultimately freeing the developer from writing some annoying checks over and over again.

@@ -441,11 +446,13 @@

@@ -454,5 +461,7 @@

+ + diff --git a/docs/articles/manage-data-columns_files/figure-html/benchmark1-1.png b/docs/articles/manage-data-columns_files/figure-html/benchmark1-1.png index bc4911c1..8d193986 100644 Binary files a/docs/articles/manage-data-columns_files/figure-html/benchmark1-1.png and b/docs/articles/manage-data-columns_files/figure-html/benchmark1-1.png differ diff --git a/docs/articles/manage-data-columns_files/figure-html/benchmark2-1.png b/docs/articles/manage-data-columns_files/figure-html/benchmark2-1.png index 0f03b540..824e6f87 100644 Binary files a/docs/articles/manage-data-columns_files/figure-html/benchmark2-1.png and b/docs/articles/manage-data-columns_files/figure-html/benchmark2-1.png differ diff --git a/docs/articles/manage-data-columns_files/figure-html/benchmark3-1.png b/docs/articles/manage-data-columns_files/figure-html/benchmark3-1.png index b6a5518a..bcbc1d19 100644 Binary files a/docs/articles/manage-data-columns_files/figure-html/benchmark3-1.png and b/docs/articles/manage-data-columns_files/figure-html/benchmark3-1.png differ diff --git a/docs/articles/parameter-list.html b/docs/articles/parameter-list.html index 43c72306..28eb1d56 100644 --- a/docs/articles/parameter-list.html +++ b/docs/articles/parameter-list.html @@ -18,7 +18,7 @@ - + +
+
-
-

-Motivation

+
+

Motivation +

The original motivation for the development of this package actually was that the author found himself writing countless checks and helper code over and over again when managing parameter lists. It became apparent that something similar to python’s dictionary would make life easier and so the idea of the container package was born.

The package has undergone some changes since it’s initial version, but the dict as a use-case for parameter lists remains very valid. So without further ado, let’s see how this works out in practice.

-library(container, warn.conflicts = FALSE)
-
-# Define some parameters
-params = dict(a = 1:10, b = "foo")
+library(container, warn.conflicts = FALSE) + +# Define some parameters +params = dict(a = 1:10, b = "foo")
-
-

-Add or Replace

+
+

Add or Replace +

With a dict the problem of accidentally overriding an existing parameter value is solved out of the box using the add function.

-params = add(params, a = 0)
-# Error: name 'a' exists already
-
-add(params, x = 0) # ok
-# {a = (1L 2L 3L 4L ...), b = "foo", x = 0}
+params = add(params, a = 0) +# Error: name 'a' exists already + +add(params, x = 0) # ok +# {a = (1L 2L 3L 4L ...), b = "foo", x = 0}

Of course, it’s also possible to indeed override a parameter.

-replace_at(params, a = 0)
-# {a = 0, b = "foo"}
+replace_at(params, a = 0) +# {a = 0, b = "foo"}

What if you intend to replace something, but there is nothing to replace?

-replace_at(params, x = 0)
-# Error: names(s) not found: 'x'
+replace_at(params, x = 0) +# Error: names(s) not found: 'x'

Now you might wonder, what if ‘I don’t care if it is replaced or added’. That’s easy.

-replace_at(params, a = 0, .add=TRUE)
-# {a = 0, b = "foo"}
-
-replace_at(params, x = 0, .add=TRUE)
-# {a = (1L 2L 3L 4L ...), b = "foo", x = 0}
+replace_at(params, a = 0, .add=TRUE) +# {a = 0, b = "foo"} + +replace_at(params, x = 0, .add=TRUE) +# {a = (1L 2L 3L 4L ...), b = "foo", x = 0}

That is, using .add = TRUE basically means, ‘replace it, or, if it is not there, just add it’

Maybe you agree that even these simple use-cases already require some effort when using base R lists.

-
-

-Extract

+
+

Extract +

When extracting a parameter, you might want to be sure it exists and signal an error otherwise.

-at(params, "x")
-# Error: index 'x' not found
-
-at(params, "a", "b")
-# {a = (1L 2L 3L 4L ...), b = "foo"}
+at(params, "x") +# Error: index 'x' not found + +at(params, "a", "b") +# {a = (1L 2L 3L 4L ...), b = "foo"}

To extract a single raw element, use at2

-at2(params, "a")
-#  [1]  1  2  3  4  5  6  7  8  9 10
+at2(params, "a") +# [1] 1 2 3 4 5 6 7 8 9 10

Alternatively, you could use the standard access operators, which behave like base R list and therefore return an empty dict (or NULL) if the index is not found.

-params["x"]
-# {}
-
-params[["x"]]
-# NULL
-
-params["a"]
-# {a = (1L 2L 3L 4L ...)}
-
-params[["a"]]
-#  [1]  1  2  3  4  5  6  7  8  9 10
-
-

-Default values

+params["x"] +# {} + +params[["x"]] +# NULL + +params["a"] +# {a = (1L 2L 3L 4L ...)} + +params[["a"]] +# [1] 1 2 3 4 5 6 7 8 9 10
+
+

Default values +

A nice property of the dict is that it provides an easy and flexible way to manage default values.

-peek_at(params, "x")
-# {}
-
-peek_at(params, "x", .default = 3:1)
-# {x = (3L 2L 1L)}
+peek_at(params, "x") +# {} + +peek_at(params, "x", .default = 3:1) +# {x = (3L 2L 1L)}

That is, if you peek at a non-existing parameter, by default an empty dict is returned, but with the option to explicitly set the default. This also works for multiple peeks.

-peek_at(params, "a", "x", "y", .default = 3:1)
-# {a = (1L 2L 3L 4L ...), x = (3L 2L 1L), y = (3L 2L 1L)}
+peek_at(params, "a", "x", "y", .default = 3:1) +# {a = (1L 2L 3L 4L ...), x = (3L 2L 1L), y = (3L 2L 1L)}
-
-

-Remove

+
+

Remove +

Similar to the above examples, the user can control how removal of existing/non-existing parameters is handled. If you expect a parameter and want to be signaled if it was not there, use delete.

-delete_at(params, "x")
-# Error: names(s) not found: 'x'
-
-delete_at(params, "a") # ok
-# {b = "foo"}
+delete_at(params, "x") +# Error: names(s) not found: 'x' + +delete_at(params, "a") # ok +# {b = "foo"}

Otherwise to loosely delete a parameter, regardless of whether it exists or not, use discard.

-discard_at(params, "a", "x")
-# {b = "foo"}
+discard_at(params, "a", "x") +# {b = "foo"}

It’s important to note, that the “base R list way” to delete elements does not work, because it just inserts a NULL.

-params[["a"]] <- NULL
-
-params
-# {a = NULL, b = "foo"}
+params[["a"]] <- NULL + +params +# {a = NULL, b = "foo"} -
-

-Merge

+
+

Merge +

Last but not least, dict allows to easily merge and/or update parameter lists.

-par1 = dict(a = 1, b = "foo")
-par2 = dict(b = "bar", x = 2, y = 3)
-
-update(par1, par2)
-# {a = 1, b = "bar", x = 2, y = 3}
+par1 = dict(a = 1, b = "foo") +par2 = dict(b = "bar", x = 2, y = 3) + +update(par1, par2) +# {a = 1, b = "bar", x = 2, y = 3}

As can be seen, existing parameters are updated and new parameters added. Using as.dict you can also do this with ordinary lists.

-update(par1, as.dict(list(b = "my b", x = 100)))
-# {a = 1, b = "my b", x = 100}
+update(par1, as.dict(list(b = "my b", x = 100))) +# {a = 1, b = "my b", x = 100}

That’s it. I hope, it will free you some time and safe some bugs next time you need to manage parameter lists.

As a very last note, keep in mind that since container version 1.0.0, dict elements are always sorted by their name, while you are still able to access elements by position (based on the sorted values).

-d = dict(x = 1, z = 2, a = 3)
-d
-# {a = 3, x = 1, z = 2}
-
-d[[1]]
-# [1] 3
-
-d[2:3]
-# {x = 1, z = 2}
+d = dict(x = 1, z = 2, a = 3) +d +# {a = 3, x = 1, z = 2} + +d[[1]] +# [1] 3 + +d[2:3] +# {x = 1, z = 2} @@ -304,11 +308,13 @@

@@ -317,5 +323,7 @@

+ + diff --git a/docs/articles/reference-semantics.html b/docs/articles/reference-semantics.html index 55e67e0c..f0e6f049 100644 --- a/docs/articles/reference-semantics.html +++ b/docs/articles/reference-semantics.html @@ -27,6 +27,8 @@ + +
+
@@ -164,32 +168,32 @@

Reference semantics

Methods that alter Container objects usually come in two versions providing either copy or reference semantics where the latter start with ‘ref_’ to note the reference semantic, for example, add() and ref_add().

Since reference semantics changes the original object, it can be used to save some typing.

-co = container()
-
-ref_add(co, a = 1)
-ref_add(co, b = 2)
-
-co
-# [a = 1, b = 2]
+co = container() + +ref_add(co, a = 1) +ref_add(co, b = 2) + +co +# [a = 1, b = 2]

Although these days this usually can be achieved equally easy using pipes.

-co = container() |>
-    add(a = 1)   |>
-    add(b = 2)
+co = container() |> + add(a = 1) |> + add(b = 2)

Still there might be use cases, where it makes your life a bit easier. Consider the following silly example.

-odds = container()
-evens = container()
-isOdd = function(x) {x %% 2 == 1}
-
-res = sapply(1:10, function(i) 
-    if(isOdd(i)) ref_add(odds, i) else ref_add(evens, i)
-)
-
-odds
-# [1L, 3L, 5L, 7L, 9L]
-evens
-# [2L, 4L, 6L, 8L, 10L]
+odds = container() +evens = container() +isOdd = function(x) {x %% 2 == 1} + +res = sapply(1:10, function(i) + if(isOdd(i)) ref_add(odds, i) else ref_add(evens, i) +) + +odds +# [1L, 3L, 5L, 7L, 9L] +evens +# [2L, 4L, 6L, 8L, 10L]

Using reference semantics for it’s side effects (as in the above example) should be really done with care though and in most cases is probably best avoided as you risk introducing unnecessary coupling into your code.

Last but not least, reference semantics can make sense when you are dealing with very large objects to avoid copying. Although, these days R often is smart enough to only copy those parts of an objects, for which a copy is really needed (copy-on-modify).

To summarize, the container package does provide reference semantics, but it should be used with care.

@@ -204,11 +208,13 @@

Reference semantics

@@ -217,5 +223,7 @@

Reference semantics

+ + diff --git a/docs/authors.html b/docs/authors.html index 81f6db3d..a72e09b6 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -1,74 +1,12 @@ - - - - - - - -Authors • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Authors and Citation • container - - + + - - - -
-
-
- -
+
- @@ -207,22 +154,20 @@

Authors

-
- - + + diff --git a/docs/index.html b/docs/index.html index fa299292..2d4565a4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ -Extending Base R List • container +Extending Base R Lists • container @@ -17,8 +17,8 @@ - - + @@ -29,6 +29,8 @@ + +
-
-

-container 1.0.1 2022-02-19 -

-
    -
  • prevent duplicated column names when renaming dict.tables
  • +
    + +
    • fix “don’t run” examples
    • +
    • fix Rd files regarding tidy HTML
    • +
    +
    + +
    • prevent duplicated column names when renaming dict.tables
    • don’t check names in dict.table constructor - allow optional checking
    • -
    -
    -
    -

    -container 1.0.0 2021-11-06 -

    -
    -

    -Breaking changes

    +
+
+ +
+

Breaking changes

This update brings some big changes and breaks some of the earlier functions. However, with version 1.0.0, from now on, the API will remain stable.

All classes Container, Deque, Set and Dict now have been modified to be more similar in the way elements can be added, extracted, replaced or removed and therefore share most of their operations. The motivation behind this was to provide specialized data structures that enhance base R list but at the same time still ‘feel’ familiar to R users. As a result, all classes (including Set and Dict) now provide named elements and access via name or integer indices similar to base R list, which should users enable to use any of them right from the start without having to read through the manual.

-

A new class dict.table is provided, a mixture of data.table and Dict, which extends data.table by Dict operations to enhance data column management.

+

A new class dict.table is provided, a mixture of data.table and Dict, which extends data.table by Dict operations to enhance data column management.

List of changes

-
    -
  • +
    • Set and Dict provide positional access
    • for Dict, internally all key-value pairs are stored in a hash-table and the elements are always sorted lexicographically by their keys
    • in addition to Set there is a new class OrderedSet, in which all elements are also always sorted.
    • @@ -227,25 +151,22 @@

      delete() (formerly remove) and discard() now always work by value. For removing elements by index, now delete_at() and discard_at() are used.
    • has() now always works by value. For checking elements by name, now has_name() is used.
    • -
    • the print() method has been fully revised and now (inspired by the sets package) prints very compact.
    • +
    • the print() method has been fully revised and now (inspired by the sets package) prints very compact.
    • -size() is now determined by length() +size() is now determined by length()
    • count(), pop, and update are now available for all classes
    • the S3 method interface now by default provides copy semantics. For reference semantics, functions starting with ref_ are used.
    • -

    -
-
-

-New features

-
    -
  • new classes OrderedSet and dict.table +
+
+

New features

+
  • new classes OrderedSet and dict.table
  • all classes support named elements
  • -names() is used to get and set the names as in base R list.
  • -
  • extract or replace parts of an object via standard [, [[, and $ operators using character or numeric indices or both at the same time.
  • +names() is used to get and set the names as in base R list. +
  • extract or replace parts of an object via standard [, [[, and $ operators using character or numeric indices or both at the same time.
  • container_options() to customize printing and applied comparison operators
  • @@ -264,62 +185,52 @@

  • arithmetic operators
  • group generic functions for Math and Summary
  • -
-
-
-

-Deprecated Functions

-
    -
  • +
+
+

Deprecated Functions

+ -
+values() - use as.list() instead +
-
-

-container 0.3.0 2018-12-01 -

+
+

Initial release

+
-
- - + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css index 1273238d..80ea5b83 100644 --- a/docs/pkgdown.css +++ b/docs/pkgdown.css @@ -56,8 +56,10 @@ img.icon { float: right; } -img { +/* Ensure in-page images don't run outside their container */ +.contents img { max-width: 100%; + height: auto; } /* Fix bug in bootstrap (only seen in firefox) */ @@ -78,11 +80,10 @@ dd { /* Section anchors ---------------------------------*/ a.anchor { - margin-left: -30px; - display:inline-block; - width: 30px; - height: 30px; - visibility: hidden; + display: none; + margin-left: 5px; + width: 20px; + height: 20px; background-image: url(./link.svg); background-repeat: no-repeat; @@ -90,17 +91,15 @@ a.anchor { background-position: center center; } -.hasAnchor:hover a.anchor { - visibility: visible; -} - -@media (max-width: 767px) { - .hasAnchor:hover a.anchor { - visibility: hidden; - } +h1:hover .anchor, +h2:hover .anchor, +h3:hover .anchor, +h4:hover .anchor, +h5:hover .anchor, +h6:hover .anchor { + display: inline-block; } - /* Fixes for fixed navbar --------------------------*/ .contents h1, .contents h2, .contents h3, .contents h4 { @@ -264,31 +263,26 @@ table { /* Syntax highlighting ---------------------------------------------------- */ -pre { - word-wrap: normal; - word-break: normal; - border: 1px solid #eee; -} - -pre, code { +pre, code, pre code { background-color: #f8f8f8; color: #333; } +pre, pre code { + white-space: pre-wrap; + word-break: break-all; + overflow-wrap: break-word; +} -pre code { - overflow: auto; - word-wrap: normal; - white-space: pre; +pre { + border: 1px solid #eee; } -pre .img { +pre .img, pre .r-plt { margin: 5px 0; } -pre .img img { +pre .img img, pre .r-plt img { background-color: #fff; - display: block; - height: auto; } code a, pre a { @@ -305,9 +299,8 @@ a.sourceLine:hover { .kw {color: #264D66;} /* keyword */ .co {color: #888888;} /* comment */ -.message { color: black; font-weight: bolder;} -.error { color: orange; font-weight: bolder;} -.warning { color: #6A0366; font-weight: bolder;} +.error {font-weight: bolder;} +.warning {font-weight: bolder;} /* Clipboard --------------------------*/ @@ -365,3 +358,27 @@ mark { content: ""; } } + +/* Section anchors --------------------------------- + Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 +*/ + +div.csl-bib-body { } +div.csl-entry { + clear: both; +} +.hanging-indent div.csl-entry { + margin-left:2em; + text-indent:-2em; +} +div.csl-left-margin { + min-width:2em; + float:left; +} +div.csl-right-inline { + margin-left:2em; + padding-left:1em; +} +div.csl-indent { + margin-left: 2em; +} diff --git a/docs/pkgdown.js b/docs/pkgdown.js index 7e7048fa..6f0eee40 100644 --- a/docs/pkgdown.js +++ b/docs/pkgdown.js @@ -80,7 +80,7 @@ $(document).ready(function() { var copyButton = ""; - $(".examples, div.sourceCode").addClass("hasCopyButton"); + $("div.sourceCode").addClass("hasCopyButton"); // Insert copy buttons: $(copyButton).prependTo(".hasCopyButton"); @@ -91,7 +91,7 @@ // Initialize clipboard: var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { text: function(trigger) { - return trigger.parentNode.textContent; + return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); } }); diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 1d0ace91..65b99950 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,5 +1,5 @@ pandoc: 2.14.0.3 -pkgdown: 1.6.1 +pkgdown: 2.0.6 pkgdown_sha: ~ articles: code-development: code-development.html @@ -8,7 +8,7 @@ articles: manage-data-columns: manage-data-columns.html parameter-list: parameter-list.html reference-semantics: reference-semantics.html -last_built: 2022-04-16T12:58Z +last_built: 2023-11-06T09:18Z urls: reference: https://github.com/rpahl/container/reference article: https://github.com/rpahl/container/articles diff --git a/docs/reference/Container.html b/docs/reference/Container.html index 1bb81d1d..ee3715bc 100644 --- a/docs/reference/Container.html +++ b/docs/reference/Container.html @@ -1,77 +1,14 @@ - - - - - - - -Container Class — Container • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Container Class — Container • container - - - - - - - - - - - - - - + + -
-
- -
- -
+

This class implements a container data structure with typical member functions to insert, delete and access elements from the container. -For the standard S3 interface, see container().

+For the standard S3 interface, see container().

+
+

Details

+

This class inherits from class Iterable and serves as the base +class for Deque, Set, and Dict.

+
+
+

See also

+ +
+
+

Author

+

Roman Pahl

+
+
+

Super class

+

container::Iterable -> Container

+
+
+

Methods

+ +

Inherited methods


+

Method new()

+

constructor

+

Usage

+

Container$new(...)

+
-

Details

+
+

Arguments

+

...
+

initial elements put into the Container

-

This class inherits from class Iterable and serves as the base -class for Deque, Set, and Dict.

-

See also

- -

Author

+

+
+
+

Returns

+

the Container object

+
-

Roman Pahl

-

Super class

+


+

Method add()

+

add element

+

Usage

+

Container$add(value, name = NULL)

+
-

container::Iterable -> Container

-

Methods

+
+

Arguments

+

value
+

value of ANY type to be added to the Container.

- -

Public methods

- - -

Inherited methods - -
- -
-

Method new()

-

constructor

Usage

-

Container$new(...)

- -

Arguments

-

-
...

initial elements put into the Container

- -

-

Returns

-

the Container object

-


-

Method add()

-

add element

Usage

-

Container$add(value, name = NULL)

-

Arguments

-

-
value

value of ANY type to be added to the Container.

+
name
+

character optional name attribute of the value.

-
name

character optional name attribute of the value.

-

-

Returns

+

+
+
+

Returns

the Container object

-


-

Method at()

+
+ +


+

Method at()

Same as at2 (see below) but accepts a vector of -indices and always returns a Container object.

Usage

-

Container$at(index)

+indices and always returns a Container object.

+

Usage

+

Container$at(index)

+
+ +
+

Arguments

+

index
+

vector of indices.

-

Arguments

-

-
index

vector of indices.

-

-

Returns

+

+
+
+

Returns

Container object with the extracted elements.

-


-

Method at2()

+
+ +


+

Method at2()

Extract value at index. If index is invalid or not found, an error is signaled. If given as a string, the element matching the name is returned. If there are two or more identical names, the value of the first match (i.e. leftmost element) is -returned.

Usage

-

Container$at2(index)

+returned.

+

Usage

+

Container$at2(index)

+
-

Arguments

-

-
index

Must be a single number > 0 or a string.

+
+

Arguments

+

index
+

Must be a single number > 0 or a string.

-

-

Returns

+ +

+
+
+

Returns

If given as a number, the element at the corresponding position, and if given as a string, the element at the corresponding name matching the given string is returned.

-


-

Method clear()

-

delete all elements from the Container

Usage

-

Container$clear()

+
-

Returns

+


+

Method clear()

+

delete all elements from the Container

+

Usage

+

Container$clear()

+
+ +
+

Returns

the cleared Container object

-


-

Method count()

-

Count number of element occurences.

Usage

-

Container$count(elem)

+
+ +


+

Method count()

+

Count number of element occurences.

+

Usage

+

Container$count(elem)

+
+ +
+

Arguments

+

elem
+

element to be counted.

-

Arguments

-

-
elem

element to be counted.

-

-

Returns

+

+
+
+

Returns

integer number of elem occurences in the Container()

-


-

Method delete()

+
+ +


+

Method delete()

Search for occurence(s) of elem in Container and remove first one that is found. If elem does not exist, an error -is signaled.

Usage

-

Container$delete(elem)

+is signaled.

+

Usage

+

Container$delete(elem)

+
+ +
+

Arguments

+

elem
+

element to be removed from the Container.

-

Arguments

-

-
elem

element to be removed from the Container.

-

-

Returns

+

+
+
+

Returns

the Container object

-


-

Method delete_at()

+
+ +


+

Method delete_at()

Delete value at given index. If index is not found, an -error is signaled.

Usage

-

Container$delete_at(index)

+error is signaled.

+

Usage

+

Container$delete_at(index)

+
+ +
+

Arguments

+

index
+

character or numeric index

-

Arguments

-

-
index

character or numeric index

-

-

Returns

+

+
+
+

Returns

the Container object

-


-

Method discard()

+
+ +


+

Method discard()

Search for occurence(s) of elem in Container and -remove first one that is found.

Usage

-

Container$discard(elem)

+remove first one that is found.

+

Usage

+

Container$discard(elem)

+
-

Arguments

-

-
elem

element to be discarded from the Container. If not +

+

Arguments

+

elem
+

element to be discarded from the Container. If not found, the operation is ignored and the object is not altered.

-

-

Returns

+ +

+
+
+

Returns

the Container object

-


-

Method discard_at()

+
+ +


+

Method discard_at()

Discard value at given index. If index is not found, -the operation is ignored.

Usage

-

Container$discard_at(index)

+the operation is ignored.

+

Usage

+

Container$discard_at(index)

+
-

Arguments

-

-
index

character or numeric index

+
+

Arguments

+

index
+

character or numeric index

-

-

Returns

+ +

+
+
+

Returns

the Container object

-


-

Method empty()

-

This function is deprecated. Use is_empty() instead.

Usage

-

Container$empty()

+
+ +


+

Method empty()

+

This function is deprecated. Use is_empty() instead.

+

Usage

+

Container$empty()

+
+ -


-

Method get_compare_fun()

+


+

Method get_compare_fun()

Get comparison function used internally by the -Container object to compare elements.

Usage

-

Container$get_compare_fun()

+Container object to compare elements.

+

Usage

+

Container$get_compare_fun()

+
+ -


-

Method has()

-

Determine if Container has some element.

Usage

-

Container$has(elem)

+


+

Method has()

+

Determine if Container has some element.

+

Usage

+

Container$has(elem)

+
-

Arguments

-

-
elem

element to search for

+
+

Arguments

+

elem
+

element to search for

-

-

Returns

+ +

+
+
+

Returns

TRUE if Container contains elem else FALSE

-


-

Method has_name()

+
+ +


+

Method has_name()

Determine if Container object contains an element with the given name. If called with no argument, the function -determines whether any element is named.

Usage

-

Container$has_name(name)

+determines whether any element is named.

+

Usage

+

Container$has_name(name)

+
-

Arguments

-

-
name

character the name

+
+

Arguments

+

name
+

character the name

-

-

Returns

+ +

+
+
+

Returns

TRUE if Container has the name otherwise FALSE

-


-

Method is_empty()

-

Check if Container is empty

Usage

-

Container$is_empty()

+
-

Returns

+


+

Method is_empty()

+

Check if Container is empty

+

Usage

+

Container$is_empty()

+
+ +
+

Returns

TRUE if the Container is empty else FALSE.

-


-

Method length()

-

Number of elements of the Container.

Usage

-

Container$length()

+
-

Returns

+


+

Method length()

+

Number of elements of the Container.

+

Usage

+

Container$length()

+
+ +
+

Returns

integer length of the Container, that is, the number of elements it contains.

-


-

Method names()

-

Names of the elements.

Usage

-

Container$names()

+
-

Returns

+


+

Method names()

+

Names of the elements.

+

Usage

+

Container$names()

+
+ +
+

Returns

character the names of the elements contained in x

-


-

Method peek_at()

+
+ +


+

Method peek_at()

Same as peek_at2 (see below) but accepts a vector of -indices and always returns a Container object.

Usage

-

Container$peek_at(index, default = NULL)

+indices and always returns a Container object.

+

Usage

+

Container$peek_at(index, default = NULL)

+
+ +
+

Arguments

+

index
+

vector of indices.

-

Arguments

-

-
index

vector of indices.

-
default

the default value to return in case the value at +

default
+

the default value to return in case the value at index is not found.

-

-

Returns

+ +

+
+
+

Returns

Container object with the extracted elements.

-


-

Method peek_at2()

+
+ +


+

Method peek_at2()

Peek at index and extract value. If index is invalid, -missing, or not not found, return default value.

Usage

-

Container$peek_at2(index, default = NULL)

+missing, or not not found, return default value.

+

Usage

+

Container$peek_at2(index, default = NULL)

+
-

Arguments

-

-
index

numeric or character index to be accessed.

+
+

Arguments

+

index
+

numeric or character index to be accessed.

-
default

the default value to return in case the value at + +

default
+

the default value to return in case the value at index is not found.

-

-

Returns

+ +

+
+
+

Returns

the value at the given index or (if not found) the given default value.

-


-

Method pop()

+
+ +


+

Method pop()

Get value at index and remove it from Container. -If index is not found, raise an error.

Usage

-

Container$pop(index)

+If index is not found, raise an error.

+

Usage

+

Container$pop(index)

+
-

Arguments

-

-
index

Must be a single number > 0 or a string.

+
+

Arguments

+

index
+

Must be a single number > 0 or a string.

-

-

Returns

+ +

+
+
+

Returns

If given as a number, the element at the corresponding position, and if given as a string, the element at the corresponding name matching the given string is returned.

-


-

Method print()

-

Print object representation

Usage

-

Container$print(...)

+
+ +


+

Method print()

+

Print object representation

+

Usage

+

Container$print(...)

+
+ +
+

Arguments

+

...
+

further arguments passed to format()

-

Arguments

-

-
...

further arguments passed to format()

-

-

Returns

+

+
+
+

Returns

invisibly returns the Container object

-


-

Method rename()

+
+ +


+

Method rename()

Rename a key in the Container. An error is signaled, if either the old key is not in the Container or the new key results -in a name-clash with an existing key.

Usage

-

Container$rename(old, new)

+in a name-clash with an existing key.

+

Usage

+

Container$rename(old, new)

+
+ +
+

Arguments

+

old
+

character name of key to be renamed.

+ -

Arguments

-

-
old

character name of key to be renamed.

+
new
+

character new key name.

-
new

character new key name.

-

-

Returns

+

+
+
+

Returns

the Container object

-


-

Method replace()

+
+ +


+

Method replace()

Replace one element by another element. Search for occurence of old and, if found, replace it by new. If old does not exist, an error is signaled, unless add was -set to TRUE, in which case new is added.

Usage

-

Container$replace(old, new, add = FALSE)

+set to TRUE, in which case new is added.

+

Usage

+

Container$replace(old, new, add = FALSE)

+
+ +
+

Arguments

+

old
+

element to be replaced

-

Arguments

-

-
old

element to be replaced

-
new

element to be put instead of old

+
new
+

element to be put instead of old

-
add

logical if TRUE the new element is added in case + +

add
+

logical if TRUE the new element is added in case old does not exists.

-

-

Returns

+ +

+
+
+

Returns

the Container object

-


-

Method replace_at()

+
+ +


+

Method replace_at()

Replace value at given index. Replace value at index by given value. If index is not found, an error is signalled, unless add was set to TRUE, in which case -new is added.

Usage

-

Container$replace_at(index, value, add = FALSE)

+new is added.

+

Usage

+

Container$replace_at(index, value, add = FALSE)

+
-

Arguments

-

-
index

character or numeric index

+
+

Arguments

+

index
+

character or numeric index

-
value

ANY new value to replace the old one.

-
add

logical if TRUE the new value element would be added +

value
+

ANY new value to replace the old one.

+ + +
add
+

logical if TRUE the new value element would be added in case index did not exists.

-

-

Returns

+ +

+
+
+

Returns

the Container object

-


-

Method remove()

-

This function is deprecated. Use delete() instead.

Usage

-

Container$remove(elem)

- -

Arguments

-

-
elem

element to be deleted from the Container. If element +

+ +


+

Method remove()

+

This function is deprecated. Use delete() instead.

+

Usage

+

Container$remove(elem)

+
+ +
+

Arguments

+

elem
+

element to be deleted from the Container. If element is not found in the Container, an error is signaled.

-

-

Returns

+ +

+
+
+

Returns

the Container object

-


-

Method size()

-

This function is deprecated. Use length() instead.

Usage

-

Container$size()

+
-

Returns

+


+

Method size()

+

This function is deprecated. Use length() instead.

+

Usage

+

Container$size()

+
+ +
+

Returns

the Container length

-


-

Method type()

-

This function is deprecated and of no real use anymore.

Usage

-

Container$type()

+
-

Returns

+


+

Method type()

+

This function is deprecated and of no real use anymore.

+

Usage

+

Container$type()

+
+ +
+

Returns

type (or mode) of internal vector containing the elements

-


-

Method update()

+
+ +


+

Method update()

Add elements of other to this if the name is -not in the Container and update elements with existing names.

Usage

-

Container$update(other)

+not in the Container and update elements with existing names.

+

Usage

+

Container$update(other)

+
+ +
+

Arguments

+

other
+

Iterable object used to update this.

-

Arguments

-

-
other

Iterable object used to update this.

-

-

Returns

+

+
+
+

Returns

returns the Container

-


-

Method values()

-

Get Container values

Usage

-

Container$values()

+
-

Returns

+


+

Method values()

+

Get Container values

+

Usage

+

Container$values()

+
+ +
+

Returns

elements of the container as a base list

-


-

Method clone()

-

The objects of this class are cloneable with this method.

Usage

-

Container$clone(deep = FALSE)

- -

Arguments

-

-
deep

Whether to make a deep clone.

- -

- - - -

Examples

-
co = Container$new(1:5, c = Container$new("a", 1), l = list()) -co$print() -
#> [(1L 2L 3L 4L ...), c = ["a", 1], l = list()]
co$length() -
#> [1] 3
co$names() -
#> [1] "" "c" "l"
co$clear() -
#> []
-# Extract -co = Container$new(a = 1, b = 2, c = 3, d = 4) -co$at(1:2) -
#> [a = 1, b = 2]
co$at(c(1, 4)) -
#> [a = 1, d = 4]
co$at(list("d", 2)) -
#> [d = 4, b = 2]
co$at2(1) -
#> [1] 1
-if (FALSE) { -co$at(0:2) # index must be > 0 -} - -co$peek_at(0:2) -
#> [a = 1, b = 2]
co$peek_at(0:2, default = 1) -
#> [1, a = 1, b = 2]
-# Replace -co$replace(4, 9) -
#> [a = 1, b = 2, c = 3, d = 9]
co$replace(9, 11) -
#> [a = 1, b = 2, c = 3, d = 11]
co$replace_at(1, -1) -
#> [a = -1, b = 2, c = 3, d = 11]
-if (FALSE) { -co$replace_at(11, 1) # index 11 exceeds length of Container -} - -# Delete -co$delete(-1) -
#> [b = 2, c = 3, d = 11]
co$delete_at(3) -
#> [b = 2, c = 3]
-if (FALSE) { -co$delete_at(3) # index 3 exceeds length of Container -} - -co$discard(3) -
#> [b = 2]
-co2 = Container$new(b = 0) -co2$add(0, name = "a") -
#> [b = 0, a = 0]
co$update(co2) -
#> [b = 0, a = 0]
co$pop(1) -
#> [1] 0
co -
#> [a = 0]
+
+ +


+

Method clone()

+

The objects of this class are cloneable with this method.

+

Usage

+

Container$clone(deep = FALSE)

+
+ +
+

Arguments

+

deep
+

Whether to make a deep clone.

+ + +

+
+ +
+ + + +
+

Examples

+
co = Container$new(1:5, c = Container$new("a", 1), l = list())
+co$print()
+#> [(1L 2L 3L 4L ...), c = ["a", 1], l = list()]
+co$length()
+#> [1] 3
+co$names()
+#> [1] ""  "c" "l"
+co$clear()
+#> []
+
+# Extract
+co = Container$new(a = 1, b = 2, c = 3, d = 4)
+co$at(1:2)
+#> [a = 1, b = 2]
+co$at(c(1, 4))
+#> [a = 1, d = 4]
+co$at(list("d", 2))
+#> [d = 4, b = 2]
+co$at2(1)
+#> [1] 1
+
+try(co$at(0:2))  # index must be > 0
+#> Error : index must be > 0
+
+co$peek_at(0:2)
+#> [a = 1, b = 2]
+co$peek_at(0:2, default = 1)
+#> [1, a = 1, b = 2]
+
+# Replace
+co$replace(4, 9)
+#> [a = 1, b = 2, c = 3, d = 9]
+co$replace(9, 11)
+#> [a = 1, b = 2, c = 3, d = 11]
+co$replace_at(1, -1)
+#> [a = -1, b = 2, c = 3, d = 11]
+
+try(co$replace_at(11, 1)) # index 11 exceeds length of Container
+#> Error : index 11 exceeds length of Container, which is 4
+
+# Delete
+co$delete(-1)
+#> [b = 2, c = 3, d = 11]
+co$delete_at(3)
+#> [b = 2, c = 3]
+
+try(co$delete_at(3))     # index 3 exceeds length of Container
+#> Error : index 3 exceeds length of Container, which is 2
+
+co$discard(3)
+#> [b = 2]
+
+co2 = Container$new(b = 0)
+co2$add(0, name = "a")
+#> [b = 0, a = 0]
+co$update(co2)
+#> [b = 0, a = 0]
+co$pop(1)
+#> [1] 0
+co
+#> [a = 0]
+
+
+ - - - + + diff --git a/docs/reference/ContainerS3.html b/docs/reference/ContainerS3.html index d2b2f92e..99018a6f 100644 --- a/docs/reference/ContainerS3.html +++ b/docs/reference/ContainerS3.html @@ -1,79 +1,16 @@ - - - - - - - -Container - Enhancing R's list — ContainerS3 • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Container - Enhancing R's list — ContainerS3 • container - - - - - - - - - - - + + - - - -
-
- -
- -
+

A container is a data structure with typical member functions to insert, delete and access elements from the container -object. It can be considered as a base R list with -extended functionality. The Container class also serves as the base -class for Deque, Set, and Dict objects.

+object. It can be considered as a base R list with +extended functionality. The Container class also serves as the base +class for Deque, Set, and Dict objects.

-
container(...)
-
-cont(...)
-
-as.container(x)
-
-as.cont(x)
-
-is.container(x)
-
-# S3 method for Container
-as.list(x, ...)
+    
+
container(...)
+
+cont(...)
+
+as.container(x)
+
+as.cont(x)
+
+is.container(x)
+
+# S3 method for Container
+as.list(x, ...)
+
+# S3 method for Container
+length(x)
+
+# S3 method for Container
+names(x)
+
+# S3 method for Container
+names(x) <- value
+
-# S3 method for Container -length(x) +
+

Arguments

+
...
+

(possibly named) elements to be put into or removed from the +Container, or additional arguments passed from and to methods.

-# S3 method for Container -names(x) -# S3 method for Container -names(x) <- value
+
x
+

R object of ANY type for as.container and is.container +or of class Container for the S3 methods.

-

Arguments

- - - - - - - - - - - - - - -
...

(possibly named) elements to be put into or removed from the -Container, or additional arguments passed from and to methods.

x

R object of ANY type for as.container and is.container -or of class Container for the S3 methods.

value

character vector of names.

-

Details

+
value
+

character vector of names.

-

Methods that alter Container objects usually come in two versions +

+
+

Details

+

Methods that alter Container objects usually come in two versions providing either copy or reference semantics where the latter start with -'ref_' to note the reference semantic, for example, add() and ref_add().

-
    -
  • container(...) initializes and returns a Container object.

  • -
- -
    -
  • cont(...) is a short cut for container(...).

  • -
- -
    -
  • as.container(x) or as.cont(x) coerce x to a Container

  • -
- -
    -
  • is.container(x) check if x is a Container

  • -
- -
    -
  • as.list(x) converts container x to a base R list. All of +'ref_' to note the reference semantic, for example, add() and ref_add().

    +
    • container(...) initializes and returns a Container object.

    • +
    • cont(...) is a short cut for container(...).

    • +
    • as.container(x) or as.cont(x) coerce x to a Container

    • +
    • as.list(x) converts container x to a base R list. All of the container's elements are copied (deeply) during the conversion.

    • -
    - -
      -
    • length(x) return the number of elements contained in x.

    • -
    - -
      -
    • names(x) return the names of the elements contained in x.

    • -
    - -
      -
    • names(x) <- value sets the names of x.

    • -
    - -
      -
    • x + y combines x and y into a new container by appending y +

    • length(x) return the number of elements contained in x.

    • +
    • names(x) return the names of the elements contained in x.

    • +
    • names(x) <- value sets the names of x.

    • +
    • x + y combines x and y into a new container by appending y to x.

    • -
    - -
      -
    • x - y element-wise discards all items of y from x, given +

    • x - y element-wise discards all items of y from x, given the element was contained in x. The result is always a container.

    • -
    - -
      -
    • x == y is TRUE if the contents of x and y are +

    • x == y is TRUE if the contents of x and y are lexicographically equal.

    • -
    - -
      -
    • x != y is TRUE if the contents of x and y are +

    • x != y is TRUE if the contents of x and y are not equal.

    • -
    - -
      -
    • x < y is TRUE if the contents of x are lexicographically +

    • x < y is TRUE if the contents of x are lexicographically less than the contents of y.

    • -
    - -
      -
    • x <= y is TRUE if the contents of x are lexicographically +

    • x <= y is TRUE if the contents of x are lexicographically less than or equal to the contents of y.

    • -
    - - - -
      -
    • at(.x, ...,) returns the value at the given indices. Indices +

    • add(.x, ...) and ref_add(.x, ...) add elements to .x.

    • +
    • at(.x, ...,) returns the value at the given indices. Indices can be letters or numbers or both. All indices must exist.

    • -
    - -
      -
    • at2(x, index) returns the value at the given index or signals an error +

    • at2(x, index) returns the value at the given index or signals an error if not found.

    • -
    - - - - - - - -
    • clear(x) and ref_clear(x) remove all elements from x.

    • +
    • clone(x) create a copy of x.

    • +
    • count(x, elem) count how often elem occurs in x.

    • +
    • delete(.x, ...) and ref_delete(.x, ...) find and remove elements. If one or more elements don't exist, an error is signaled.

    • -
    - -
    • delete_at(.x, ...) and ref_delete_at(.x, ...) find and remove values at given indices. If any given index is invalid, an error is signaled.

    • -
    - -
    • discard(.x, ...) and ref_discard(.x, ...) find and discard elements. Elements that don't exist, are ignored.

    • -
    - -
    • discard_at(.x, ...) and ref_discard_at(.x, ...) find and discard values at given indices. Invalid indices are ignored.

    • -
    - -
      -
    • has(x, elem) TRUE if element is in x and otherwise FALSE.

    • -
    - - - -
      -
    • is_empty(x) TRUE if object is empty otherwise FALSE

    • -
    - -
    • has(x, elem) TRUE if element is in x and otherwise FALSE.

    • +
    • has_name(x, name) check if name is in x

    • +
    • is_empty(x) TRUE if object is empty otherwise FALSE

    • +
    • peek_at(x, ..., .default = NULL) returns the value at the given indices or (if not found) the given default value.

    • -
    - -
    • peek_at2(x, index, default) returns the value at the given index or (if not found) the given default value.

    • -
    - -
    • ref_pop(.x, index) return element at given index and remove it from the container object.

    • -
    - -
    • rename(.x, old, new) and ref_rename(.x, old, new) rename one or more keys from old to new, respectively, by copy and in place (i.e. by reference).

    • -
    - -
    • replace(.x, old, new, add = FALSE) and +ref_replace(.x, old, new, add = FALSE) try to find element old and replace it with element new. If old does not exist, an error is raised, unless add was set to TRUE.

    • -
    - -
    • replace_at(.x, .., .add = FALSE) and ref_replace_at(.x, ..., .add = FALSE) replace values at given indices. If a given index is invalid, an error is signaled unless .add was set to TRUE.

    • -
    - -

    See also

    - -

    For the class documentation see Container. -Objects of the derived classes can be created by deque, setnew, and -dict.

    - -

    Examples

    -
    co = container(1:5, c = container("a", 1), l = list()) -is.container(co) -
    #> [1] TRUE
    print(co) -
    #> [(1L 2L 3L 4L ...), c = ["a", 1], l = list()]
    length(co) -
    #> [1] 3
    names(co) -
    #> [1] "" "c" "l"
    -unpack(co) # flatten recursively similar to unlist -
    #> c1 c2 -#> "1" "2" "3" "4" "5" "a" "1"
    -# Math -co = container(1, 2, -(3:5)) -co -
    #> [1, 2, (-3L -4L -5L)]
    abs(co) -
    #> [1, 2, 3, 4, 5]
    cumsum(co) -
    #> [1, 3, 0, -4, -9]
    round(co) -
    #> [1, 2, -3, -4, -5]
    exp(co) -
    #> [2.718282, 7.389056, 0.04978707, 0.01831564, 0.006737947]
    -# Summary -range(co) -
    #> [1] -5 2
    min(co) -
    #> [1] -5
    max(co) -
    #> [1] 2
    -# Arithmetic -c1 = container(1, 1:2) -c2 = container(2, 1:2) -c1 + c2 # same as c(c1, c2) -
    #> [1, (1L 2L), 2, (1L 2L)]
    c2 + c1 # same as c(c2, c1) -
    #> [2, (1L 2L), 1, (1L 2L)]
    -c1 - c2 -
    #> [1]
    c2 - c1 -
    #> [2]
    c1 - c1 -
    #> []
    -# Comparison -c1 = container(1, 2, 3) -c2 = container(1, 3, 2) -c1 == c1 # TRUE -
    #> [1] TRUE
    c1 != c2 # TRUE -
    #> [1] TRUE
    c1 <= c1 # TRUE -
    #> [1] TRUE
    c1 == c2 # FALSE -
    #> [1] FALSE
    c1 < c2 # TRUE -
    #> [1] TRUE
    c1 < container(2) # TRUE -
    #> [1] TRUE
    c1 < container() # FALSE -
    #> [1] FALSE
    -# Extract or replace -co = container(a = 1, b = 2, c = 3, d = 4) -co[1:2] -
    #> [a = 1, b = 2]
    co[1, 4] -
    #> [a = 1, d = 4]
    co["d", 2] -
    #> [d = 4, b = 2]
    co[list("d", 2)] -
    #> [d = 4, b = 2]
    co[0:10] -
    #> [a = 1, b = 2, c = 3, d = 4]
    -co = container(a = 1, b = 2) -co[[1]] -
    #> [1] 1
    co[["a"]] -
    #> [1] 1
    co[["x"]] -
    #> NULL
    co = container(a = 1, b = "bar") -(co[1:2] <- 1:2) -
    #> [1] 1 2
    -if (FALSE) { -co[3] <- 3 # index out of range -} -(co[list(1, "b")] <- 3:4) # mixed numeric/character index -
    #> [1] 3 4
    -co = container(a = 1, b = 2) -co[[1]] <- 9 -co[["b"]] <- 8 -co[["x"]] <- 7 -co$z <- 99 -print(co) -
    #> [a = 9, b = 8, x = 7, z = 99]
    -# Replace 8 by 0 -co[[{8}]] <- 0 -print(co) -
    #> [a = 9, b = 0, x = 7, z = 99]
    - -co = container(a = 1, b = "bar") -co$f <- 3 -co$b <- 2 -co -
    #> [a = 1, b = 2, f = 3]
    - -co = container(1) -add(co, 1, b = 2, c = container(1:3)) -
    #> [1, 1, b = 2, c = [(1L 2L 3L)]]
    - -co = container(a = 1, 2, b = 3, 4) -at(co, 1:3) -
    #> [a = 1, 2, b = 3]
    at(co, "a", "b", 2) -
    #> [a = 1, b = 3, 2]
    if (FALSE) { -at(co, "x") # index 'x' not found -at(co, 1:10) # index 5 exceeds length of Container -} - -co = container(a = 1, 2, b = 3, 4) -at2(co, 1) -
    #> [1] 1
    at2(co, "a") -
    #> [1] 1
    at2(co, 2) -
    #> [1] 2
    if (FALSE) { -at2(co, "x") # index 'x' not found -at2(co, 5) # index 5 exceeds length of Container -} - -co = container(1, 2, mean) -clear(co) -
    #> []
    print(co) # Original was not touched -
    #> [1, 2, <<function>>]
    ref_clear(co) # Clears original -print(co) -
    #> []
    -co = container(1, 2, 3) -co2 = clone(co) -co == co2 -
    #> [1] TRUE
    -co = container("a", "b", "a", mean, mean) -count(co, "a") -
    #> [1] 2
    count(co, mean) -
    #> [1] 2
    count(co, "c") -
    #> [1] 0
    -co = container("a", 1:3, iris) -print(co) -
    #> ["a", (1L 2L 3L), <<data.frame(150x5)>>]
    delete(co, 1:3, "a") -
    #> [<<data.frame(150x5)>>]
    delete(co, iris) -
    #> ["a", (1L 2L 3L)]
    if (FALSE) { -delete(co, "b") # "b" is not in Container -} - -co = container(a = 1, b = 2, 3) -delete_at(co, "a", "b") # [3] -
    #> [3]
    delete_at(co, 1:2) # [3] -
    #> [3]
    delete_at(co, "a", 3) # [b = 2] -
    #> [b = 2]
    if (FALSE) { -delete_at(co, 4) # index out of range -delete_at(co, "x") # names(s) not found: 'x' -} +
+
+

See also

+

For the class documentation see Container. +Objects of the derived classes can be created by deque, setnew, and +dict.

+
-co = container("a", num = 1:3, data = iris) -print(co) -
#> ["a", num = (1L 2L 3L), data = <<data.frame(150x5)>>]
discard(co, 1:3, "a") -
#> [data = <<data.frame(150x5)>>]
discard(co, iris) -
#> ["a", num = (1L 2L 3L)]
discard(co, "b") # ignored -
#> ["a", num = (1L 2L 3L), data = <<data.frame(150x5)>>]
-co = container(a = 1, b = 2, 3) -discard_at(co, "a", "b") # [3] -
#> [3]
discard_at(co, 1:2) # [3] -
#> [3]
discard_at(co, "a", 3) # [b = 2] -
#> [b = 2]
discard_at(co, "x") # ignored -
#> [a = 1, b = 2, 3]
-co = container(1, 2, mean) -has(co, 1) # TRUE -
#> [1] TRUE
has(co, mean) # TRUE -
#> [1] TRUE
has(co, 1:2) # FALSE -
#> [1] FALSE
-co = container(a = 1, 2, f = mean) -has_name(co, "a") # TRUE -
#> [1] TRUE
has_name(co, "f") # TRUE -
#> [1] TRUE
has_name(co, "2") # FALSE -
#> [1] FALSE
-co = container(1, 2) -is_empty(co) -
#> [1] FALSE
#> [1] TRUE
-co = container(a = 1, 2, b = 3, 4) -peek_at(co, 1) -
#> [a = 1]
peek_at(co, "a") -
#> [a = 1]
peek_at(co, "x") -
#> []
peek_at(co, "x", .default = 0) -
#> [x = 0]
peek_at(co, "a", "x", 2, 9, .default = -1) -
#> [a = 1, x = -1, 2, -1]
-co = container(a = 1, 2, b = 3, 4) -peek_at2(co, 1) -
#> [1] 1
peek_at2(co, "a") -
#> [1] 1
peek_at2(co, "x") -
#> NULL
peek_at2(co, "x", default = 0) -
#> [1] 0
-co = container(a = 1, b = 1:3, d = "foo") -ref_pop(co, "b") -
#> [1] 1 2 3
ref_pop(co, 1) -
#> [1] 1
-if (FALSE) { -ref_pop(co, "x") # index 'x' not found -} -co = container(a = 1, b = 2, 3) -rename(co, c("a", "b"), c("a1", "y")) -
#> [a1 = 1, y = 2, 3]
print(co) -
#> [a = 1, b = 2, 3]
ref_rename(co, c("a", "b"), c("a1", "y")) -
#> [a1 = 1, y = 2, 3]
print(co) -
#> [a1 = 1, y = 2, 3]
-co = container("x", 9) -replace(co, 9, 0) -
#> ["x", 0]
replace(co, "x", 0) -
#> [0, 9]
if (FALSE) { -replace(co, "z", 0) # old element ("z") is not in Container -} -replace(co, "z", 0, add = TRUE) # ok, adds the element -
#> ["x", 9, 0]
-co = container(a = 0, b = "z") -replace_at(co, a = 1, b = 2) -
#> [a = 1, b = 2]
replace_at(co, 1:2, 1:2) # same -
#> [a = 1L, b = 2L]
replace_at(co, c("a", "b"), list(1, 2)) # same -
#> [a = 1, b = 2]
-if (FALSE) { -replace_at(co, x = 1) # names(s) not found: 'x' -} -replace_at(co, x = 1, .add = TRUE) # ok (adds x = 1) -
#> [a = 0, b = "z", x = 1]
+
+

Examples

+
co = container(1:5, c = container("a", 1), l = list())
+is.container(co)
+#> [1] TRUE
+print(co)
+#> [(1L 2L 3L 4L ...), c = ["a", 1], l = list()]
+length(co)
+#> [1] 3
+names(co)
+#> [1] ""  "c" "l"
+
+unpack(co)   # flatten recursively similar to unlist
+#>                      c1  c2 
+#> "1" "2" "3" "4" "5" "a" "1" 
+
+# Math
+co = container(1, 2, -(3:5))
+co
+#> [1, 2, (-3L -4L -5L)]
+abs(co)
+#> [1, 2, 3, 4, 5]
+cumsum(co)
+#> [1, 3, 0, -4, -9]
+round(co)
+#> [1, 2, -3, -4, -5]
+exp(co)
+#> [2.718282, 7.389056, 0.04978707, 0.01831564, 0.006737947]
+
+# Summary
+range(co)
+#> [1] -5  2
+min(co)
+#> [1] -5
+max(co)
+#> [1] 2
+
+# Arithmetic
+c1 = container(1, 1:2)
+c2 = container(2, 1:2)
+c1 + c2     # same as c(c1, c2)
+#> [1, (1L 2L), 2, (1L 2L)]
+c2 + c1     # same as c(c2, c1)
+#> [2, (1L 2L), 1, (1L 2L)]
+
+c1 - c2
+#> [1]
+c2 - c1
+#> [2]
+c1 - c1
+#> []
+
+# Comparison
+c1 = container(1, 2, 3)
+c2 = container(1, 3, 2)
+c1 == c1            # TRUE
+#> [1] TRUE
+c1 != c2            # TRUE
+#> [1] TRUE
+c1 <= c1            # TRUE
+#> [1] TRUE
+c1 == c2            # FALSE
+#> [1] FALSE
+c1 < c2             # TRUE
+#> [1] TRUE
+c1 < container(2)   # TRUE
+#> [1] TRUE
+c1 < container()    # FALSE
+#> [1] FALSE
+
+# Extract or replace
+co = container(a = 1, b = 2, c = 3, d = 4)
+co[1:2]
+#> [a = 1, b = 2]
+co[1, 4]
+#> [a = 1, d = 4]
+co["d", 2]
+#> [d = 4, b = 2]
+co[list("d", 2)]
+#> [d = 4, b = 2]
+co[0:10]
+#> [a = 1, b = 2, c = 3, d = 4]
+
+co = container(a = 1, b = 2)
+co[[1]]
+#> [1] 1
+co[["a"]]
+#> [1] 1
+co[["x"]]
+#> NULL
+co = container(a = 1, b = "bar")
+(co[1:2] <- 1:2)
+#> [1] 1 2
+
+try({
+co[3] <- 3 # index out of range
+})
+#> Error : index out of range (length = 2): 3
+(co[list(1, "b")] <- 3:4)   # mixed numeric/character index
+#> [1] 3 4
+
+co = container(a = 1, b = 2)
+co[[1]] <- 9
+co[["b"]] <- 8
+co[["x"]] <- 7
+co$z <- 99
+print(co)
+#> [a = 9, b = 8, x = 7, z = 99]
+
+# Replace 8 by 0
+co[[{8}]] <- 0
+print(co)
+#> [a = 9, b = 0, x = 7, z = 99]
+
+
+co = container(a = 1, b = "bar")
+co$f <- 3
+co$b <- 2
+co
+#> [a = 1, b = 2, f = 3]
+
+
+co = container(1)
+add(co, 1, b = 2, c = container(1:3))
+#> [1, 1, b = 2, c = [(1L 2L 3L)]]
+
+
+co = container(a = 1, 2, b = 3, 4)
+at(co, 1:3)
+#> [a = 1, 2, b = 3]
+at(co, "a", "b", 2)
+#> [a = 1, b = 3, 2]
+try(at(co, "x"))     # index 'x' not found
+#> Error : index 'x' not found
+try(at(co, 1:10))    # index 5 exceeds length of Container
+#> Error : index 5 exceeds length of Container, which is 4
+
+co = container(a = 1, 2, b = 3, 4)
+at2(co, 1)
+#> [1] 1
+at2(co, "a")
+#> [1] 1
+at2(co, 2)
+#> [1] 2
+try(at2(co, "x"))     # index 'x' not found
+#> Error : index 'x' not found
+try(at2(co, 5))       # index 5 exceeds length of Container
+#> Error : index 5 exceeds length of Container, which is 4
+
+co = container(1, 2, mean)
+clear(co)
+#> []
+print(co)    # Original was not touched
+#> [1, 2, <<function>>]
+ref_clear(co)   # Clears original
+print(co)
+#> []
+
+co = container(1, 2, 3)
+co2 = clone(co)
+co == co2
+#> [1] TRUE
+
+co = container("a", "b", "a", mean, mean)
+count(co, "a")
+#> [1] 2
+count(co, mean)
+#> [1] 2
+count(co, "c")
+#> [1] 0
+
+co = container("a", 1:3, iris)
+print(co)
+#> ["a", (1L 2L 3L), <<data.frame(150x5)>>]
+delete(co, 1:3, "a")
+#> [<<data.frame(150x5)>>]
+delete(co, iris)
+#> ["a", (1L 2L 3L)]
+try({
+delete(co, "b")   # "b" is not in Container
+})
+#> Error : "b" is not in Container
+
+co = container(a = 1, b = 2, 3)
+delete_at(co, "a", "b")          # [3]
+#> [3]
+delete_at(co, 1:2)               # [3]
+#> [3]
+delete_at(co, "a", 3)            # [b = 2]
+#> [b = 2]
+try({
+ delete_at(co, 4)                 # index out of range
+ delete_at(co, "x")               # names(s) not found: 'x'
+})
+#> Error : index out of range (length = 3): 4
+
+co = container("a", num = 1:3, data = iris)
+print(co)
+#> ["a", num = (1L 2L 3L), data = <<data.frame(150x5)>>]
+discard(co, 1:3, "a")
+#> [data = <<data.frame(150x5)>>]
+discard(co, iris)
+#> ["a", num = (1L 2L 3L)]
+discard(co, "b")  # ignored
+#> ["a", num = (1L 2L 3L), data = <<data.frame(150x5)>>]
+
+co = container(a = 1, b = 2, 3)
+discard_at(co, "a", "b")         # [3]
+#> [3]
+discard_at(co, 1:2)              # [3]
+#> [3]
+discard_at(co, "a", 3)           # [b = 2]
+#> [b = 2]
+discard_at(co, "x")              # ignored
+#> [a = 1, b = 2, 3]
+
+co = container(1, 2, mean)
+has(co, 1)                   # TRUE
+#> [1] TRUE
+has(co, mean)                # TRUE
+#> [1] TRUE
+has(co, 1:2)                 # FALSE
+#> [1] FALSE
+
+co = container(a = 1, 2, f = mean)
+has_name(co, "a")    # TRUE
+#> [1] TRUE
+has_name(co, "f")    # TRUE
+#> [1] TRUE
+has_name(co, "2")    # FALSE
+#> [1] FALSE
+
+co = container(1, 2)
+is_empty(co)
+#> [1] FALSE
+is_empty(clear(co))
+#> [1] TRUE
+
+co = container(a = 1, 2, b = 3, 4)
+peek_at(co, 1)
+#> [a = 1]
+peek_at(co, "a")
+#> [a = 1]
+peek_at(co, "x")
+#> []
+peek_at(co, "x", .default = 0)
+#> [x = 0]
+peek_at(co, "a", "x", 2, 9, .default = -1)
+#> [a = 1, x = -1, 2, -1]
+
+co = container(a = 1, 2, b = 3, 4)
+peek_at2(co, 1)
+#> [1] 1
+peek_at2(co, "a")
+#> [1] 1
+peek_at2(co, "x")
+#> NULL
+peek_at2(co, "x", default = 0)
+#> [1] 0
+
+co = container(a = 1, b = 1:3, d = "foo")
+ref_pop(co, "b")
+#> [1] 1 2 3
+ref_pop(co, 1)
+#> [1] 1
+
+try({
+ref_pop(co, "x")  # index 'x' not found
+})
+#> Error : index 'x' not found
+co = container(a = 1, b = 2, 3)
+rename(co, c("a", "b"), c("a1", "y"))
+#> [a1 = 1, y = 2, 3]
+print(co)
+#> [a = 1, b = 2, 3]
+ref_rename(co, c("a", "b"), c("a1", "y"))
+#> [a1 = 1, y = 2, 3]
+print(co)
+#> [a1 = 1, y = 2, 3]
+
+co = container("x", 9)
+replace(co, 9, 0)
+#> ["x", 0]
+replace(co, "x", 0)
+#> [0, 9]
+try({
+replace(co, "z", 0)              # old element ("z") is not in Container
+})
+#> Error : old element ("z") is not in Container
+replace(co, "z", 0, add = TRUE)  # ok, adds the element
+#> ["x", 9, 0]
+
+co = container(a = 0, b = "z")
+replace_at(co, a = 1, b = 2)
+#> [a = 1, b = 2]
+replace_at(co, 1:2, 1:2)                 # same
+#> [a = 1L, b = 2L]
+replace_at(co, c("a", "b"), list(1, 2))  # same
+#> [a = 1, b = 2]
+
+try({
+replace_at(co, x = 1)                    # names(s) not found: 'x'
+})
+#> Error : names(s) not found: 'x'
+replace_at(co, x = 1, .add = TRUE)       # ok (adds x = 1)
+#> [a = 0, b = "z", x = 1]
+
+
+
- - - + + diff --git a/docs/reference/Deque.html b/docs/reference/Deque.html index e6edf4a6..0201754e 100644 --- a/docs/reference/Deque.html +++ b/docs/reference/Deque.html @@ -1,78 +1,15 @@ - - - - - - - -Deque Class — Deque • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Deque Class — Deque • container - - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -204,186 +130,239 @@

Deque Class

Deques are a generalization of stacks and queues typically with methods to add, delete and access elements at both sides of the underlying data sequence. As such, the Deque can also be used to mimic -both stacks and queues. For the standard S3 interface, see deque().

+both stacks and queues. For the standard S3 interface, see deque().

+
+

Details

+

This class inherits from class Container() and extends it by +popleft and peek methods, and reverse and rotate functionality.

+
+
+

See also

+ +
+
+

Super classes

+

container::Iterable -> container::Container -> Deque

+
+
+

Methods

+ +

Inherited methods


+

Method addleft()

+

Add element to left side of the Deque.

+

Usage

+

Deque$addleft(value, name = NULL)

+
-

Details

+
+

Arguments

+

value
+

value of ANY type to be added to the Deque.

-

This class inherits from class Container() and extends it by -popleft and peek methods, and reverse and rotate functionality.

-

See also

- -

Super classes

+
name
+

character optional name attribute of the value.

-

container::Iterable -> container::Container -> Deque

-

Methods

- -

Public methods

- - -

Inherited methods - -
- -
-

Method addleft()

-

Add element to left side of the Deque.

Usage

-

Deque$addleft(value, name = NULL)

- -

Arguments

-

-
value

value of ANY type to be added to the Deque.

- -
name

character optional name attribute of the value.

- -

-

Returns

+

+
+
+

Returns

the Deque object.

-


-

Method peek()

-

Peek at last element of the Deque.

Usage

-

Deque$peek(default = NULL)

+
+ +


+

Method peek()

+

Peek at last element of the Deque.

+

Usage

+

Deque$peek(default = NULL)

+
+ +
+

Arguments

+

default
+

returned default value if Deque is empty.

-

Arguments

-

-
default

returned default value if Deque is empty.

-

-

Returns

+

+
+
+

Returns

element 'peeked' on the right

-


-

Method peekleft()

-

Peek at first element of the Deque.

Usage

-

Deque$peekleft(default = NULL)

+
+ +


+

Method peekleft()

+

Peek at first element of the Deque.

+

Usage

+

Deque$peekleft(default = NULL)

+
+ +
+

Arguments

+

default
+

returned default value if Deque is empty.

-

Arguments

-

-
default

returned default value if Deque is empty.

-

-

Returns

+

+
+
+

Returns

element 'peeked' on the left

-


-

Method popleft()

-

Delete and return element from the left side of the Deque().

Usage

-

Deque$popleft()

+
-

Returns

+


+

Method popleft()

+

Delete and return element from the left side of the Deque().

+

Usage

+

Deque$popleft()

+
+ +
+

Returns

element 'popped' from the left side of the Deque()

-


-

Method rev()

-

Reverse all elements of the Deque() in-place.

Usage

-

Deque$rev()

+
-

Returns

+


+

Method rev()

+

Reverse all elements of the Deque() in-place.

+

Usage

+

Deque$rev()

+
+ +
+

Returns

the Deque() object.

-


-

Method rotate()

+
+ +


+

Method rotate()

Rotate all elements n steps to the right. If n is -negative, rotate to the left.

Usage

-

Deque$rotate(n = 1L)

+negative, rotate to the left.

+

Usage

+

Deque$rotate(n = 1L)

+
+ +
+

Arguments

+

n
+

integer number of steps to rotate

-

Arguments

-

-
n

integer number of steps to rotate

-

-

Returns

+

+
+
+

Returns

returns the Deque() object.

-


-

Method clone()

-

The objects of this class are cloneable with this method.

Usage

-

Deque$clone(deep = FALSE)

- -

Arguments

-

-
deep

Whether to make a deep clone.

- -

- - - -

Examples

-
d = Deque$new(1, 2, s = "a", v = 1:3) -d$addleft(0) -
#> |0, 1, 2, s = "a", v = (1L 2L 3L)|
d$peekleft() -
#> [1] 0
d$peek() -
#> [1] 1 2 3
-d$popleft() -
#> [1] 0
d$rev() -
#> |v = (1L 2L 3L), s = "a", 2, 1|
-d$rotate() -
#> |1, v = (1L 2L 3L), s = "a", 2|
d$rotate(2) -
#> |"a", 2, 1, v = (1L 2L 3L)|
d$rotate(-3) -
#> |v = (1L 2L 3L), "a", 2, 1|
+
+ +


+

Method clone()

+

The objects of this class are cloneable with this method.

+

Usage

+

Deque$clone(deep = FALSE)

+
+ +
+

Arguments

+

deep
+

Whether to make a deep clone.

+ + +

+
+ +
+ +
+ +
+

Examples

+
d = Deque$new(1, 2, s = "a", v = 1:3)
+d$addleft(0)
+#> |0, 1, 2, s = "a", v = (1L 2L 3L)|
+d$peekleft()
+#> [1] 0
+d$peek()
+#> [1] 1 2 3
+
+d$popleft()
+#> [1] 0
+d$rev()
+#> |v = (1L 2L 3L), s = "a", 2, 1|
+
+d$rotate()
+#> |1, v = (1L 2L 3L), s = "a", 2|
+d$rotate(2)
+#> |"a", 2, 1, v = (1L 2L 3L)|
+d$rotate(-3)
+#> |v = (1L 2L 3L), "a", 2, 1|
+
+
+
- - - + + diff --git a/docs/reference/Dict.html b/docs/reference/Dict.html index 09cc5405..9a0b1e8d 100644 --- a/docs/reference/Dict.html +++ b/docs/reference/Dict.html @@ -1,77 +1,14 @@ - - - - - - - -Dict Class — Dict • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Dict Class — Dict • container - - - - - - - - - - - - - - + + -
-
- -
- -
+

The Dict() resembles Python's dict type, and is implemented -as a specialized associative Container(). +as a specialized associative Container(). For the standard S3 interface, see dict().

- -

Details

- -

This class inherits from class Container() and overwrides some +

+

Details

+

This class inherits from class Container() and overwrides some methods to account for the associative key-value pair semantic. Internally, all key-value pairs are stored in a hash-table and the elements are always sorted lexicographically by their keys.

-

See also

+
+
+

See also

+ +
+
+

Super classes

+

container::Iterable -> container::Container -> Dict

+
+
+

Methods

+ +

Inherited methods



+

Method add()

If name not yet in Dict, insert value at name, -otherwise signal an error.

Usage

-

Dict$add(name, value)

+otherwise signal an error.

+

Usage

+

Dict$add(name, value)

+
+ +
+

Arguments

+

name
+

character variable name under which to store value.

+ -

Arguments

-

-
name

character variable name under which to store value.

+
value
+

the value to be added to the Dict.

-
value

the value to be added to the Dict.

-

-

Returns

+

+
+
+

Returns

the Dict object

-


-

Method discard_at()

+
+ +


+

Method discard_at()

Discard value at given index. If index is not found, -the operation is ignored.

Usage

-

Dict$discard_at(index)

+the operation is ignored.

+

Usage

+

Dict$discard_at(index)

+
+ +
+

Arguments

+

index
+

character or numeric index

-

Arguments

-

-
index

character or numeric index

-

-

Returns

+

+
+
+

Returns

the Dict object

-


-

Method get()

-

This function is deprecated. Use at2() instead.

Usage

-

Dict$get(key)

+
+ +


+

Method get()

+

This function is deprecated. Use at2() instead.

+

Usage

+

Dict$get(key)

+
-

Arguments

-

-
key

character name of key.

+
+

Arguments

+

key
+

character name of key.

-

-

Returns

+ +

+
+
+

Returns

If key in Dict, return value at key, else throw error.

-


-

Method keys()

-

Get all keys.

Usage

-

Dict$keys()

+
-

Returns

+


+

Method keys()

+

Get all keys.

+

Usage

+

Dict$keys()

+
+ +
+

Returns

character vector of all keys.

-


-

Method remove()

-

This function is deprecated. Use delete() instead.

Usage

-

Dict$remove(key)

+
-

Arguments

-

-
key

character name of key.

+


+

Method remove()

+

This function is deprecated. Use delete() instead.

+

Usage

+

Dict$remove(key)

+
-

-

Returns

+
+

Arguments

+

key
+

character name of key.

+ + +

+
+
+

Returns

If key in Dict, remove it, otherwise raise an error.

-


-

Method replace()

+
+ +


+

Method replace()

Replace one element by another element. Search for occurence of old and, if found, replace it by new. -If old does not exist, an error is signaled.

Usage

-

Dict$replace(old, new)

+If old does not exist, an error is signaled.

+

Usage

+

Dict$replace(old, new)

+
-

Arguments

-

-
old

element to be replaced

+
+

Arguments

+

old
+

element to be replaced

-
new

element to be put instead of old

-

-

Returns

+
new
+

element to be put instead of old

+ + +

+
+
+

Returns

the Dict object

-


-

Method set()

-

This function is deprecated. Use replace() instead.

Usage

-

Dict$set(key, value, add = FALSE)

+
+ +


+

Method set()

+

This function is deprecated. Use replace() instead.

+

Usage

+

Dict$set(key, value, add = FALSE)

+
+ +
+

Arguments

+

key
+

character name of key.

-

Arguments

-

-
key

character name of key.

-
value

the value to be set

+
value
+

the value to be set

-
add

logical if TRUE the value is set regardless whether + +

add
+

logical if TRUE the value is set regardless whether key already exists in Dict.

-

-

Returns

+ +

+
+
+

Returns

returns the Dict

-


-

Method sort()

+
+ +


+

Method sort()

Sort elements according to their keys. This function -is deprecated as keys are now always sorted.

Usage

-

Dict$sort(decr = FALSE)

+is deprecated as keys are now always sorted.

+

Usage

+

Dict$sort(decr = FALSE)

+
-

Arguments

-

-
decr

logical if TRUE sort in decreasing order.

+
+

Arguments

+

decr
+

logical if TRUE sort in decreasing order.

-

-

Returns

+ +

+
+
+

Returns

returns the Dict

-


-

Method update()

+
+ +


+

Method update()

Add elements of other to this if the name is -not in the Dict and update elements with existing names.

Usage

-

Dict$update(other)

+not in the Dict and update elements with existing names.

+

Usage

+

Dict$update(other)

+
+ +
+

Arguments

+

other
+

Iterable object used to update this.

-

Arguments

-

-
other

Iterable object used to update this.

-

-

Returns

+

+
+
+

Returns

returns the updated Dict object.

-


-

Method values()

-

Get Container values

Usage

-

Dict$values()

+
+ +


+

Method values()

+

Get Container values

+

Usage

+

Dict$values()

+
-

Returns

+
+

Returns

a copy of all elements in a list

-


-

Method clone()

-

The objects of this class are cloneable with this method.

Usage

-

Dict$clone(deep = FALSE)

- -

Arguments

-

-
deep

Whether to make a deep clone.

- -

- - - -

Examples

-
d = Dict$new(o = "one", na = NA, a = 1) -d -
#> {a = 1, na = NA, o = "one"}
d$keys() -
#> [1] "a" "na" "o"
-d$add("li", list(1, 2)) -
#> {a = 1, li = list(1, 2), na = NA, o = "one"}
d$discard_at("na") -
#> {a = 1, li = list(1, 2), o = "one"}
d$replace(1, 9) -
#> {a = 9, li = list(1, 2), o = "one"}
-d2 = Dict$new(a = 0, b = 1) -d$update(d2) -
#> {a = 0, b = 1, li = list(1, 2), o = "one"}
+
+ +


+

Method clone()

+

The objects of this class are cloneable with this method.

+

Usage

+

Dict$clone(deep = FALSE)

+
+ +
+

Arguments

+

deep
+

Whether to make a deep clone.

+ + +

+
+ +
+ +
+ +
+

Examples

+
d = Dict$new(o = "one", na = NA, a = 1)
+d
+#> {a = 1, na = NA, o = "one"}
+d$keys()
+#> [1] "a"  "na" "o" 
+
+d$add("li", list(1, 2))
+#> {a = 1, li = list(1, 2), na = NA, o = "one"}
+d$discard_at("na")
+#> {a = 1, li = list(1, 2), o = "one"}
+d$replace(1, 9)
+#> {a = 9, li = list(1, 2), o = "one"}
+
+d2 = Dict$new(a = 0, b = 1)
+d$update(d2)
+#> {a = 0, b = 1, li = list(1, 2), o = "one"}
+
+
+ - - - + + diff --git a/docs/reference/Iterable.html b/docs/reference/Iterable.html index 09e6d1f2..0907c84e 100644 --- a/docs/reference/Iterable.html +++ b/docs/reference/Iterable.html @@ -1,79 +1,16 @@ - - - - - - - -Iterable abstract class interface — Iterable • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Iterable abstract class interface — Iterable • container - - - - - - - - - - - - - - + + -
-
- -
- -
+
-

An Iterable is an object that provides an iter() method, -which is expected to return an Iterator object. This class defines the +

An Iterable is an object that provides an iter() method, +which is expected to return an Iterator object. This class defines the abstract class interface such that each class inheriting this class provides -an iter() method and must implement a private method create_iter(), -which must return an Iterator object.

+an iter() method and must implement a private method create_iter(), +which must return an Iterator object.

- -

See also

- - -

Author

- +
+

See also

+ +
+
+

Author

Roman Pahl

-

Methods

- +
+
+

Methods

-

Public methods

+


+

Method new()

+

Iterable is an abstract class and thus cannot be instantiated.

+

Usage

+

Iterable$new()

+
- -


-

Method new()

-

Iterable is an abstract class and thus cannot be instantiated.

Usage

-

Iterable$new()

-


-

Method iter()

-

Create iterator

Usage

-

Iterable$iter()

+


+

Method iter()

+

Create iterator

+

Usage

+

Iterable$iter()

+
-

Returns

+
+

Returns

returns the Iterator object.

-


-

Method clone()

-

The objects of this class are cloneable with this method.

Usage

-

Iterable$clone(deep = FALSE)

+
-

Arguments

-

-
deep

Whether to make a deep clone.

+


+

Method clone()

+

The objects of this class are cloneable with this method.

+

Usage

+

Iterable$clone(deep = FALSE)

+
-

+
+

Arguments

+

deep
+

Whether to make a deep clone.

+

+
+ +
+ +
+
-
- - + + diff --git a/docs/reference/Iterator.html b/docs/reference/Iterator.html index d96267bd..2214a984 100644 --- a/docs/reference/Iterator.html +++ b/docs/reference/Iterator.html @@ -1,78 +1,15 @@ - - - - - - - -Iterator Class — Iterator • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Iterator Class — Iterator • container - - - - - - - - - - - - - - + + -
-
- -
- -
+
@@ -204,197 +130,278 @@

Iterator Class

An Iterator is an object that allows to iterate over sequences. It implements next_iter and get_value to iterate and retrieve the value of the sequence it is associated with. -For the standard S3 interface, see iter().

+For the standard S3 interface, see iter().

+
+ + +
+

Author

+

Roman Pahl

+
+

Methods

+ +


+

Method new()

+

Iterator constructor

+

Usage

+

Iterator$new(x, .subset = .subset2)

+
+
+

Arguments

+

x
+

object to iterate over

-

Author

+
.subset
+

accessor function

-

Roman Pahl

-

Methods

- -

Public methods

- - -


-

Method new()

-

Iterator constructor

Usage

-

Iterator$new(x, .subset = .subset2)

- -

Arguments

-

-
x

object to iterate over

- -
.subset

accessor function

- -

-

Returns

+

+
+
+

Returns

invisibly returns the Iterator object

-


-

Method begin()

+
+ +


+

Method begin()

set iterator to the first element of the underlying sequence unless length of sequence is zero, in which case it will -point to nothing.

Usage

-

Iterator$begin()

+point to nothing.

+

Usage

+

Iterator$begin()

+
-

Returns

+
+

Returns

invisibly returns the Iterator object

-


-

Method get_value()

-

get value where the iterator points to

Usage

-

Iterator$get_value()

+
+ +


+

Method get_value()

+

get value where the iterator points to

+

Usage

+

Iterator$get_value()

+
-

Returns

+
+

Returns

returns the value the Iterator is pointing at.

-


-

Method get_next()

-

get next value

Usage

-

Iterator$get_next()

+
+ +


+

Method get_next()

+

get next value

+

Usage

+

Iterator$get_next()

+
-

Returns

+
+

Returns

increments the iterator and returns the value the Iterator is pointing to.

-


-

Method has_next()

-

check if iterator has more elements

Usage

-

Iterator$has_next()

+
+ +


+

Method has_next()

+

check if iterator has more elements

+

Usage

+

Iterator$has_next()

+
-

Returns

+
+

Returns

TRUE if iterator has next element else FALSE

-


-

Method has_value()

-

check if iterator points at value

Usage

-

Iterator$has_value()

+
-

Returns

+


+

Method has_value()

+

check if iterator points at value

+

Usage

+

Iterator$has_value()

+
+ +
+

Returns

TRUE if iterator points at value otherwise FALSE

-


-

Method length()

-

iterator length

Usage

-

Iterator$length()

+
-

Returns

+


+

Method length()

+

iterator length

+

Usage

+

Iterator$length()

+
+ +
+

Returns

number of elements to iterate

-


-

Method pos()

-

get iterator position

Usage

-

Iterator$pos()

+
-

Returns

+


+

Method pos()

+

get iterator position

+

Usage

+

Iterator$pos()

+
+ +
+

Returns

integer if iterator has next element else FALSE

-


-

Method next_iter()

-

increment iterator

Usage

-

Iterator$next_iter()

+
+ +


+

Method next_iter()

+

increment iterator

+

Usage

+

Iterator$next_iter()

+
-

Returns

+
+

Returns

invisibly returns the Iterator object

-


-

Method print()

-

print method

Usage

-

Iterator$print()

+
+ +


+

Method print()

+

print method

+

Usage

+

Iterator$print()

+
-


-

Method reset_iter()

-

reset iterator to '0'

Usage

-

Iterator$reset_iter()

-

Returns

+


+

Method reset_iter()

+

reset iterator to '0'

+

Usage

+

Iterator$reset_iter()

+
+ +
+

Returns

invisibly returns the Iterator object

-


-

Method clone()

-

The objects of this class are cloneable with this method.

Usage

-

Iterator$clone(deep = FALSE)

- -

Arguments

-

-
deep

Whether to make a deep clone.

- -

- - - -

Examples

-
-# Numeric Vector -v = 1:3 -it = Iterator$new(v) -it -
#> <Iterator> at position 0 / 3
-if (FALSE) { -it$get_value() # iterator does not point at a value -} - -it$has_value() -
#> [1] FALSE
it$has_next() -
#> [1] TRUE
it$next_iter() -
#> <Iterator> at position 1 / 3
it$get_value() -
#> [1] 1
it$get_next() -
#> [1] 2
it$get_next() -
#> [1] 3
it -
#> <Iterator> at position 3 / 3
it$has_next() -
#> [1] FALSE
it$begin() -
#> <Iterator> at position 1 / 3
it$get_value() -
#> [1] 1
it$reset_iter() -
#> <Iterator> at position 0 / 3
-# Works by reference for Container -co = Container$new(1, 2, 3) -it = co$iter() -it$get_next() -
#> [[1]] -#> [1] 1 -#>
co$discard(2) -
#> [1, 3]
it -
#> <Iterator> at position 1 / 2
it$get_value() -
#> [[1]] -#> [1] 1 -#>
co$discard(1) -
#> [3]
it -
#> <Iterator> at position 1 / 1
it$get_value() -
#> [[1]] -#> [1] 3 -#>
it$begin() -
#> <Iterator> at position 1 / 1
+
+ +


+

Method clone()

+

The objects of this class are cloneable with this method.

+

Usage

+

Iterator$clone(deep = FALSE)

+
+ +
+

Arguments

+

deep
+

Whether to make a deep clone.

+ + +

+
+ +
+ +
+ +
+

Examples

+

+# Numeric Vector
+v = 1:3
+it = Iterator$new(v)
+it
+#> <Iterator> at position 0 / 3 
+
+try(it$get_value())  # iterator does not point at a value
+#> Error in it$get_value() : iterator does not point at a value
+
+it$has_value()
+#> [1] FALSE
+it$has_next()
+#> [1] TRUE
+it$next_iter()
+#> <Iterator> at position 1 / 3 
+it$get_value()
+#> [1] 1
+it$get_next()
+#> [1] 2
+it$get_next()
+#> [1] 3
+it
+#> <Iterator> at position 3 / 3 
+it$has_next()
+#> [1] FALSE
+it$begin()
+#> <Iterator> at position 1 / 3 
+it$get_value()
+#> [1] 1
+it$reset_iter()
+#> <Iterator> at position 0 / 3 
+
+# Works by reference for Container
+co = Container$new(1, 2, 3)
+it = co$iter()
+it$get_next()
+#> [[1]]
+#> [1] 1
+#> 
+co$discard(2)
+#> [1, 3]
+it
+#> <Iterator> at position 1 / 2 
+it$get_value()
+#> [[1]]
+#> [1] 1
+#> 
+co$discard(1)
+#> [3]
+it
+#> <Iterator> at position 1 / 1 
+it$get_value()
+#> [[1]]
+#> [1] 3
+#> 
+it$begin()
+#> <Iterator> at position 1 / 1 
+
+
+
- - - + + diff --git a/docs/reference/OpsArithmetic.html b/docs/reference/OpsArithmetic.html index 7b56dda4..5a2179da 100644 --- a/docs/reference/OpsArithmetic.html +++ b/docs/reference/OpsArithmetic.html @@ -1,76 +1,13 @@ - - - - - - - -Arithmetic Operators — OpsArithmetic • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Arithmetic Operators — OpsArithmetic • container - + + - - - -
-
- -
- -
+
-

Binary arithmetic operators for Container() objects and +

Binary arithmetic operators for Container() objects and derived classes.

-
# S3 method for Container
+    
+
# S3 method for Container
 +(x, y)
 
 # S3 method for Container
@@ -225,102 +152,139 @@ 

Arithmetic Operators

+(x, y) # S3 method for Set --(x, y)
- -

Arguments

- - - - - - -
x, y

Depending on the operator at least one must be of class -Container() or the respective derived class and the other at least be -coercible to the respective class.

- -

Value

- -

For Container, x + y combines x and y into a new container +-(x, y)

+
+ +
+

Arguments

+
x, y
+

Depending on the operator at least one must be of class +Container() or the respective derived class and the other at least be +coercible to the respective class.

+ +
+
+

Value

+ + +

For Container, x + y combines x and y into a new container by appending y to x.

-

For Container, x - y element-wise discards all items of y -from x, given the element was contained in x. The result is always a + + +

For Container, x - y element-wise discards all items of y

+ + +

from x, given the element was contained in x. The result is always a container.

-

For Deque, x + y combines x and y into a new deque by + + +

For Deque,

+

+

x + y combines x and y into a new deque by appending y to x.

+ +

For Deque, x - y element-wise removes all items of y from x, given the element was contained in x.

+ +

For Dict, x + y combines x and y into a new dict by updating x by y (see also [update()]).

+ +

For Dict, x - y removes all keys from x that appear in y.

+ +

For Set, x + y performs the set union.

+ +

For Set, x - y performs the set difference.

+
-

Examples

-
c1 = container(1, 1:2) -c2 = container(2, 1:2) -c1 + c2 # same as c(c1, c2) -
#> [1, (1L 2L), 2, (1L 2L)]
c2 + c1 # same as c(c2, c1) -
#> [2, (1L 2L), 1, (1L 2L)]
-c1 - c2 -
#> [1]
c2 - c1 -
#> [2]
c1 - c1 -
#> []
# Arithmetic -d1 = deque(1, 1:2) -d2 = deque(2, 1:2) -d1 + d2 # same as c(d1, d2) -
#> |1, (1L 2L), 2, (1L 2L)|
d2 + d1 # same as c(d2, d1) -
#> |2, (1L 2L), 1, (1L 2L)|
-d1 - d2 -
#> |1|
d2 - d1 -
#> |2|
d1 - d1 -
#> ||
-# Arithmetic -d1 = dict(a = 1, b = list(1, 2)) -d2 = dict(a = 2, b = list(1, 2)) -d1 + d2 # same as update(d, d2) -
#> {a = 2, b = list(1, 2)}
d2 + d1 # same as update(d2, d) -
#> {a = 1, b = list(1, 2)}
if (FALSE) { -c(d1, d2) # duplicated keys are not allowed for Dict -} -d1 - d2 -
#> {}
d2 - d1 -
#> {}
d1 - d1 -
#> {}
-# Arithmetic -s1 = setnew(1, 1:2) -s2 = setnew(2, 1:2) -s1 + s2 # same as s1 | s2 or c(c1, s2) -
#> {1, (1L 2L), 2}
s2 + s1 # same -
#> {2, (1L 2L), 1}
-s1 - s2 -
#> {1}
s2 - s1 -
#> {2}
-
+
+

Examples

+
c1 = container(1, 1:2)
+c2 = container(2, 1:2)
+c1 + c2     # same as c(c1, c2)
+#> [1, (1L 2L), 2, (1L 2L)]
+c2 + c1     # same as c(c2, c1)
+#> [2, (1L 2L), 1, (1L 2L)]
+
+c1 - c2
+#> [1]
+c2 - c1
+#> [2]
+c1 - c1
+#> []
+# Arithmetic
+d1 = deque(1, 1:2)
+d2 = deque(2, 1:2)
+d1 + d2     # same as c(d1, d2)
+#> |1, (1L 2L), 2, (1L 2L)|
+d2 + d1     # same as c(d2, d1)
+#> |2, (1L 2L), 1, (1L 2L)|
+
+d1 - d2
+#> |1|
+d2 - d1
+#> |2|
+d1 - d1
+#> ||
+
+# Arithmetic
+d1 = dict(a = 1, b = list(1, 2))
+d2 = dict(a = 2, b = list(1, 2))
+d1 + d2      # same as update(d, d2)
+#> {a = 2, b = list(1, 2)}
+d2 + d1      # same as update(d2, d)
+#> {a = 1, b = list(1, 2)}
+try({
+c(d1, d2)    # duplicated keys are not allowed for Dict
+})
+#> Error : duplicated keys are not allowed
+d1 - d2
+#> {}
+d2 - d1
+#> {}
+d1 - d1
+#> {}
+
+# Arithmetic
+s1 = setnew(1, 1:2)
+s2 = setnew(2, 1:2)
+s1 + s2     # same as s1 | s2 or c(c1, s2)
+#> {1, (1L 2L), 2}
+s2 + s1     # same
+#> {2, (1L 2L), 1}
+
+s1 - s2
+#> {1}
+s2 - s1
+#> {2}
+
+
+
+
- - - + + diff --git a/docs/reference/OpsCompare.html b/docs/reference/OpsCompare.html index b6ac2763..01333b75 100644 --- a/docs/reference/OpsCompare.html +++ b/docs/reference/OpsCompare.html @@ -1,76 +1,13 @@ - - - - - - - -Comparison Operators — OpsCompare • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Comparison Operators — OpsCompare • container - - - - + + -
-
- -
- -
+
-

Binary comparison operators for Container() objects and +

Binary comparison operators for Container() objects and derived classes.

-
# S3 method for Container
+    
+
# S3 method for Container
 ==(x, y)
 
 # S3 method for Container
@@ -219,68 +146,69 @@ 

Comparison Operators

&lt;=(x, y) # S3 method for Container -&gt;=(x, y)
- -

Arguments

- - - - - - -
x, y

at least one must be a Container() object (or an object of -one of the derived classes) while the other must be at least iterable.

+&gt;=(x, y)
+
-

Details

+
+

Arguments

+
x, y
+

at least one must be a Container() object (or an object of +one of the derived classes) while the other must be at least iterable.

+
+
+

Details

-
    -
  • x == y is TRUE if the contents of x and y are lexicographically equal.

  • +
    • x == y is TRUE if the contents of x and y are lexicographically equal.

    • x != y is TRUE if the contents of x and y are not equal.

    • x < y is TRUE if the contents of x are lexicographically less than the contents of y.

    • x <= y is TRUE if the contents of x are lexicographically less than or equal to the contents of y.

    • -
    - - -

    Examples

    -
    c1 = container(1, 2, 3) -c2 = container(1, 3, 2) -c1 == c1 # TRUE -
    #> [1] TRUE
    c1 != c2 # TRUE -
    #> [1] TRUE
    c1 <= c1 # TRUE -
    #> [1] TRUE
    c1 == c2 # FALSE -
    #> [1] FALSE
    c1 < c2 # TRUE -
    #> [1] TRUE
    c1 < container(2) # TRUE -
    #> [1] TRUE
    c1 < container() # FALSE -
    #> [1] FALSE
    -
    +
+ +
+

Examples

+
c1 = container(1, 2, 3)
+c2 = container(1, 3, 2)
+c1 == c1            # TRUE
+#> [1] TRUE
+c1 != c2            # TRUE
+#> [1] TRUE
+c1 <= c1            # TRUE
+#> [1] TRUE
+c1 == c2            # FALSE
+#> [1] FALSE
+c1 < c2             # TRUE
+#> [1] TRUE
+c1 < container(2)   # TRUE
+#> [1] TRUE
+c1 < container()    # FALSE
+#> [1] FALSE
+
+
+
+
- - - + + diff --git a/docs/reference/OpsExtract.html b/docs/reference/OpsExtract.html index c9e30dee..9ed1263a 100644 --- a/docs/reference/OpsExtract.html +++ b/docs/reference/OpsExtract.html @@ -1,76 +1,13 @@ - - - - - - - -Extract Parts of a Container Object — OpsExtract • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Extract Parts of a Container Object — OpsExtract • container - - - - + + -
-
- -
- -
+
@@ -203,72 +129,78 @@

Extract Parts of a Container Object

to R's base extract operators on lists.

-
# S3 method for Container
+    
+
# S3 method for Container
 [(x, ...)
 
 # S3 method for Container
-[[(x, i)
+[[(x, i)
+
+ +
+

Arguments

+
x
+

Container object from which to extract elements.

-

Arguments

- - - - - - - - - - -
x

Container object from which to extract elements.

i, ...

indices specifying elements to extract. Indices -are numeric or character vectors or a list containing both.

-

Details

+
i, ...
+

indices specifying elements to extract. Indices +are numeric or character vectors or a list containing both.

-

[ selects multiple values. The indices can be numeric or +

+
+

Details

+

[ selects multiple values. The indices can be numeric or character or both. They can be passed as a vector or list or, for convenience, just as a comma-separated sequence (see Examples). Non-existing indices are ignored.

-

[[ selects a single value using a numeric or character index.

+

[[ selects a single value using a numeric or character index.

+
-

Examples

-
co = container(a = 1, b = 2, c = 3, d = 4) -co[1:2] -
#> [a = 1, b = 2]
co[1, 4] -
#> [a = 1, d = 4]
co["d", 2] -
#> [d = 4, b = 2]
co[list("d", 2)] -
#> [d = 4, b = 2]
co[0:10] -
#> [a = 1, b = 2, c = 3, d = 4]
-co = container(a = 1, b = 2) -co[[1]] -
#> [1] 1
co[["a"]] -
#> [1] 1
co[["x"]] -
#> NULL
+
+

Examples

+
co = container(a = 1, b = 2, c = 3, d = 4)
+co[1:2]
+#> [a = 1, b = 2]
+co[1, 4]
+#> [a = 1, d = 4]
+co["d", 2]
+#> [d = 4, b = 2]
+co[list("d", 2)]
+#> [d = 4, b = 2]
+co[0:10]
+#> [a = 1, b = 2, c = 3, d = 4]
+
+co = container(a = 1, b = 2)
+co[[1]]
+#> [1] 1
+co[["a"]]
+#> [1] 1
+co[["x"]]
+#> NULL
+
+
+ - - - + + diff --git a/docs/reference/OpsLogic.html b/docs/reference/OpsLogic.html index 37d7691e..73be90bc 100644 --- a/docs/reference/OpsLogic.html +++ b/docs/reference/OpsLogic.html @@ -1,76 +1,13 @@ - - - - - - - -Logic Operators — OpsLogic • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Logic Operators — OpsLogic • container - - - - + + -
-
- -
- -
+
-

Binary logic operators for Container() objects and +

Binary logic operators for Container() objects and derived classes.

-
# S3 method for Dict
+    
+
# S3 method for Dict
 &amp;(x, y)
 
 # S3 method for Dict
@@ -213,51 +140,48 @@ 

Logic Operators

&amp;(x, y) # S3 method for Set -|(x, y)
- -

Arguments

- - - - - - -
x, y

Depending on the operator at least one must be of class -Container() or the respective derived class and the other at least be -coercible to the respective class.

- +|(x, y)
+
-

Examples

-
d1 = dict(a = 1, b = 2) -d2 = dict(a = 10, x = 4) -d1 & d2 # {a = 1} -
#> {a = 1}
-
+
+

Arguments

+
x, y
+

Depending on the operator at least one must be of class +Container() or the respective derived class and the other at least be +coercible to the respective class.

+ +
+ +
+

Examples

+
d1 = dict(a = 1, b = 2)
+d2 = dict(a = 10, x = 4)
+d1 & d2      # {a = 1}
+#> {a = 1}
+
+
+
+
- - - + + diff --git a/docs/reference/OpsReplace.html b/docs/reference/OpsReplace.html index 163835ce..da7cc43f 100644 --- a/docs/reference/OpsReplace.html +++ b/docs/reference/OpsReplace.html @@ -1,76 +1,13 @@ - - - - - - - -Replace Parts of a Container — OpsReplace • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Replace Parts of a Container — OpsReplace • container - + + - - - -
-
- -
- -
+
@@ -203,39 +129,38 @@

Replace Parts of a Container

to R's base replace operators on lists.

-
# S3 method for Container
+    
+
# S3 method for Container
 [(x, i) <- value
 
 # S3 method for Container
 [[(x, i) <- value
 
 # S3 method for Container
-$(x, name) <- value
+$(x, name) <- value
+
+ +
+

Arguments

+
x
+

Container object in which to replace elements.

-

Arguments

- - - - - - - - - - - - - - - - - - -
x

Container object in which to replace elements.

i

indices specifying elements to replace. Indices -are numeric or character vectors or a list containing both.

value

the replacing value of ANY type

name

character string (possibly backtick quoted)

-

Details

+
i
+

indices specifying elements to replace. Indices +are numeric or character vectors or a list containing both.

+ +
value
+

the replacing value of ANY type

+ + +
name
+

character string (possibly backtick quoted)

+ +
+
+

Details

[<- replaces multiple values. The indices can be numeric or character or both. They can be passed as a vector or list. Values can be added by 'replacing' at new indices, which only works for character @@ -245,59 +170,64 @@

Details passing the element in curly braces (see Examples), that is, the object is searched for the element and then the element is replaced by the value.

$<- replaces a single element at a given name.

+

-

Examples

-
co = container(a = 1, b = "bar") -(co[1:2] <- 1:2) -
#> [1] 1 2
-if (FALSE) { -co[3] <- 3 # index out of range -} -(co[list(1, "b")] <- 3:4) # mixed numeric/character index -
#> [1] 3 4
-co = container(a = 1, b = 2) -co[[1]] <- 9 -co[["b"]] <- 8 -co[["x"]] <- 7 -co$z <- 99 -print(co) -
#> [a = 9, b = 8, x = 7, z = 99]
-# Replace 8 by 0 -co[[{8}]] <- 0 -print(co) -
#> [a = 9, b = 0, x = 7, z = 99]
- -co = container(a = 1, b = "bar") -co$f <- 3 -co$b <- 2 -co -
#> [a = 1, b = 2, f = 3]
-
+
+

Examples

+
co = container(a = 1, b = "bar")
+(co[1:2] <- 1:2)
+#> [1] 1 2
+
+try({
+co[3] <- 3 # index out of range
+})
+#> Error : index out of range (length = 2): 3
+(co[list(1, "b")] <- 3:4)   # mixed numeric/character index
+#> [1] 3 4
+
+co = container(a = 1, b = 2)
+co[[1]] <- 9
+co[["b"]] <- 8
+co[["x"]] <- 7
+co$z <- 99
+print(co)
+#> [a = 9, b = 8, x = 7, z = 99]
+
+# Replace 8 by 0
+co[[{8}]] <- 0
+print(co)
+#> [a = 9, b = 0, x = 7, z = 99]
+
+
+co = container(a = 1, b = "bar")
+co$f <- 3
+co$b <- 2
+co
+#> [a = 1, b = 2, f = 3]
+
+
+
+ - - - + + diff --git a/docs/reference/OrderedSet.html b/docs/reference/OrderedSet.html index 6617e809..b911cf28 100644 --- a/docs/reference/OrderedSet.html +++ b/docs/reference/OrderedSet.html @@ -1,76 +1,13 @@ - - - - - - - -OrderedSet Class — OrderedSet • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -OrderedSet Class — OrderedSet • container - - - - + + -
-
- -
- -
+
-

The OrderedSet is a Set where all elements are always +

The OrderedSet is a Set where all elements are always ordered.

- -

Details

- -

The order of elements is determined sequentially as follows:

    -
  • element's length

  • +
    +

    Details

    +

    The order of elements is determined sequentially as follows:

    • element's length

    • whether it is an atomic element

    • the element's class(es)

    • by numeric value (if applicable)

    • it's representation when printed

    • -
    • the name of the element in the Set

    • -
    - -

    See also

    +
  • the name of the element in the Set

  • +
+
+

See also

+ +
+
+

Super classes

+

container::Iterable -> container::Container -> container::Set -> OrderedSet

+
+
+

Methods

+ +

Inherited methods


+

Method new()

+

OrderedSet constructor

+

Usage

+

OrderedSet$new(...)

+
- -

Super classes

+ +
+

Returns

returns the OrderedSet object

-


-

Method add()

-

Add element

Usage

-

OrderedSet$add(value, name = NULL)

+
+ +


+

Method add()

+

Add element

+

Usage

+

OrderedSet$add(value, name = NULL)

+
-

Arguments

-

-
value

value of ANY type to be added to the OrderedSet.

+
+

Arguments

+

value
+

value of ANY type to be added to the OrderedSet.

-
name

character optional name attribute of the value.

-

-

Returns

+
name
+

character optional name attribute of the value.

+ + +

+
+
+

Returns

the OrderedSet object.

-


-

Method clone()

-

The objects of this class are cloneable with this method.

Usage

-

OrderedSet$clone(deep = FALSE)

+
-

Arguments

-

-
deep

Whether to make a deep clone.

+


+

Method clone()

+

The objects of this class are cloneable with this method.

+

Usage

+

OrderedSet$clone(deep = FALSE)

+
-

+
+

Arguments

+

deep
+

Whether to make a deep clone.

+

+
-

Examples

-
s1 = OrderedSet$new(2, 1) -s1 -
#> {1, 2}
+
+ +
+ +
+

Examples

+
s1 = OrderedSet$new(2, 1)
+s1
+#> {1, 2}
+
+
+
- - - + + diff --git a/docs/reference/Set.html b/docs/reference/Set.html index 81855368..0312770b 100644 --- a/docs/reference/Set.html +++ b/docs/reference/Set.html @@ -1,78 +1,15 @@ - - - - - - - -Set Class — Set • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Set Class — Set • container - - - - - - - - - - - - - - + + -
-
- -
- -
+

The Set is considered and implemented as a specialized -Container, that is, elements are always unique in the Container and +Container, that is, elements are always unique in the Container and it provides typical set operations such as union and intersect. -For the standard S3 interface, see setnew().

+For the standard S3 interface, see setnew().

+
+

See also

+ +
+
+

Super classes

+

container::Iterable -> container::Container -> Set

+
+
+

Methods

+ +

Inherited methods



+

Method add()

+

Add element

+

Usage

+

Set$add(value, name = NULL)

+
+ +
+

Arguments

+

value
+

value of ANY type to be added to the Set.

-

Arguments

-

-
value

value of ANY type to be added to the Set.

-
name

character optional name attribute of the value.

+
name
+

character optional name attribute of the value.

-

-

Returns

+ +

+
+
+

Returns

the Set object.

-


-

Method diff()

-

Set difference

Usage

-

Set$diff(s)

+
+ +


+

Method diff()

+

Set difference

+

Usage

+

Set$diff(s)

+
-

Arguments

-

-
s

Set object to 'subtract'

+
+

Arguments

+

s
+

Set object to 'subtract'

-

-

Returns

+ +

+
+
+

Returns

the Set object updated as a result of the set difference between this and s.

-


-

Method intersect()

-

Set intersection

Usage

-

Set$intersect(s)

+
+ +


+

Method intersect()

+

Set intersection

+

Usage

+

Set$intersect(s)

+
+ +
+

Arguments

+

s
+

Set object to 'intersect'

-

Arguments

-

-
s

Set object to 'intersect'

-

-

Returns

+

+
+
+

Returns

the Set object as a result of the intersection of this and s.

-


-

Method union()

-

Set union

Usage

-

Set$union(s)

+
+ +


+

Method union()

+

Set union

+

Usage

+

Set$union(s)

+
+ +
+

Arguments

+

s
+

Set object to be 'unified'

-

Arguments

-

-
s

Set object to be 'unified'

-

-

Returns

+

+
+
+

Returns

the Set object as a result of the union of this and s.

-


-

Method is_equal()

-

Set equality

Usage

-

Set$is_equal(s)

+
+ +


+

Method is_equal()

+

Set equality

+

Usage

+

Set$is_equal(s)

+
-

Arguments

-

-
s

Set object to compare against

+
+

Arguments

+

s
+

Set object to compare against

-

-

Returns

+ +

+
+
+

Returns

TRUE if this is equal to s, otherwise FALSE

-


-

Method is_subset()

-

Set proper subset

Usage

-

Set$is_subset(s)

+
+ +


+

Method is_subset()

+

Set proper subset

+

Usage

+

Set$is_subset(s)

+
+ +
+

Arguments

+

s
+

Set object to compare against

-

Arguments

-

-
s

Set object to compare against

-

-

Returns

+

+
+
+

Returns

TRUE if this is subset of s, otherwise FALSE

-


-

Method is_proper_subset()

-

Set subset

Usage

-

Set$is_proper_subset(s)

+
+ +


+

Method is_proper_subset()

+

Set subset

+

Usage

+

Set$is_proper_subset(s)

+
+ +
+

Arguments

+

s
+

Set object to compare against

-

Arguments

-

-
s

Set object to compare against

-

-

Returns

+

+
+
+

Returns

TRUE if this is proper subset of s, otherwise FALSE

-


-

Method values()

-

Get Set values

Usage

-

Set$values()

+
-

Returns

+


+

Method values()

+

Get Set values

+

Usage

+

Set$values()

+
+ +
+

Returns

elements of the set as a base list

-


-

Method clone()

-

The objects of this class are cloneable with this method.

Usage

-

Set$clone(deep = FALSE)

- -

Arguments

-

-
deep

Whether to make a deep clone.

- -

- - - -

Examples

-
s1 = Set$new(1, 2) -s1 -
#> {1, 2}
s1$add(1) -
#> {1, 2}
s1$add(3) -
#> {1, 2, 3}
s2 = Set$new(3, 4, 5) -s1$union(s2) -
#> {1, 2, 3, 4, 5}
s1 -
#> {1, 2, 3, 4, 5}
-s1 = Set$new(1, 2, 3) -s1$intersect(s2) -
#> {3}
s1 -
#> {3}
-s1$diff(s2) -
#> {}
s1$diff(s1) -
#> {}
s1 -
#> {}
+
+ +


+

Method clone()

+

The objects of this class are cloneable with this method.

+

Usage

+

Set$clone(deep = FALSE)

+
+ +
+

Arguments

+

deep
+

Whether to make a deep clone.

+ + +

+
+ +
+ +
+ +
+

Examples

+
s1 = Set$new(1, 2)
+s1
+#> {1, 2}
+s1$add(1)
+#> {1, 2}
+s1$add(3)
+#> {1, 2, 3}
+s2 = Set$new(3, 4, 5)
+s1$union(s2)
+#> {1, 2, 3, 4, 5}
+s1
+#> {1, 2, 3, 4, 5}
+
+s1 = Set$new(1, 2, 3)
+s1$intersect(s2)
+#> {3}
+s1
+#> {3}
+
+s1$diff(s2)
+#> {}
+s1$diff(s1)
+#> {}
+s1
+#> {}
+
+
+
- - - + + diff --git a/docs/reference/add.html b/docs/reference/add.html index d8d0d0f9..6de76b99 100644 --- a/docs/reference/add.html +++ b/docs/reference/add.html @@ -1,75 +1,12 @@ - - - - - - - -Add Elements to Containers — add • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Add Elements to Containers — add • container - - + + - - -
-
- -
- -
+
@@ -201,118 +127,123 @@

Add Elements to Containers

Add elements to container-like objects.

-
add(.x, ...)
-
-ref_add(.x, ...)
-
-# S3 method for Container
-add(.x, ...)
-
-# S3 method for Container
-ref_add(.x, ...)
-
-# S3 method for Dict
-add(.x, ...)
-
-# S3 method for Dict
-ref_add(.x, ...)
+    
+
add(.x, ...)
+
+ref_add(.x, ...)
+
+# S3 method for Container
+add(.x, ...)
+
+# S3 method for Container
+ref_add(.x, ...)
+
+# S3 method for Dict
+add(.x, ...)
+
+# S3 method for Dict
+ref_add(.x, ...)
+
+# S3 method for dict.table
+add(.x, ...)
+
+# S3 method for dict.table
+ref_add(.x, ...)
+
-# S3 method for dict.table -add(.x, ...) +
+

Arguments

+
.x
+

an R object of the respective class.

-# S3 method for dict.table -ref_add(.x, ...)
-

Arguments

- - - - - - - - - - -
.x

an R object of the respective class.

...

elements to be added.

+
...
+

elements to be added.

-

Value

+
+
+

Value

+ -

For Container, an object of class Container (or one of the +

For Container, an object of class Container (or one of the respective derived classes).

-

For dict.table an object of class -dict.table.

-

Note

+ +

For dict.table an object of class +dict.table.

+
+
+

Note

While add uses copy semantics ref_add works by reference.

-

If .x is a Container, Set or Deque object, the elements being added +

If .x is a Container, Set or Deque object, the elements being added can (but must not) be named.

-

If .x is a Dict or dict.table object, +

If .x is a Dict or dict.table object, all elements must be of the form key = value. If one of the keys already exists, an error is given.

+
-

Examples

-
-co = container(1) -add(co, 1, b = 2, c = container(1:3)) -
#> [1, 1, b = 2, c = [(1L 2L 3L)]]
-s = setnew(1) -add(s, 1, 1, b = 2, "1", co = container(1, 1)) -
#> {1, b = 2, "1", co = [1, 1]}
-d = dict(a = 1) -add(d, b = 2, co = container(1:3)) -
#> {a = 1, b = 2, co = [(1L 2L 3L)]}
-if (FALSE) { -add(d, a = 7:9) # key 'a' already in Dict -} - -dit = dict.table(a = 1:3) -add(dit, b = 3:1, d = 4:6) -
#> <dict.table> with 3 rows and 3 columns -#> a b d -#> 1: 1 3 4 -#> 2: 2 2 5 -#> 3: 3 1 6
-if (FALSE) { -add(dit, a = 7:9) # column 'a' already exists -} - -dit = dict.table(a = 1:3) -add(dit, b = 3:1, d = 4:6) -
#> <dict.table> with 3 rows and 3 columns -#> a b d -#> 1: 1 3 4 -#> 2: 2 2 5 -#> 3: 3 1 6
-if (FALSE) { -add(dit, a = 7:9) # column 'a' already exists -} -
+
+

Examples

+

+co = container(1)
+add(co, 1, b = 2, c = container(1:3))
+#> [1, 1, b = 2, c = [(1L 2L 3L)]]
+
+s = setnew(1)
+add(s, 1, 1, b = 2, "1", co = container(1, 1))
+#> {1, b = 2, "1", co = [1, 1]}
+
+d = dict(a = 1)
+add(d, b = 2, co = container(1:3))
+#> {a = 1, b = 2, co = [(1L 2L 3L)]}
+
+try(add(d, a = 7:9))  # key 'a' already in Dict
+#> Error : name 'a' exists already
+
+dit = dict.table(a = 1:3)
+add(dit, b = 3:1, d = 4:6)
+#> <dict.table> with 3 rows and 3 columns
+#>    a b d
+#> 1: 1 3 4
+#> 2: 2 2 5
+#> 3: 3 1 6
+
+try(add(dit, a = 7:9))  # column 'a' already exists
+#> Error : name 'a' exists already
+
+dit = dict.table(a = 1:3)
+add(dit, b = 3:1, d = 4:6)
+#> <dict.table> with 3 rows and 3 columns
+#>    a b d
+#> 1: 1 3 4
+#> 2: 2 2 5
+#> 3: 3 1 6
+
+try(add(dit, a = 7:9))  # column 'a' already exists
+#> Error : name 'a' exists already
+
+
+
- - - + + diff --git a/docs/reference/addleft.html b/docs/reference/addleft.html index 68eabf9d..c8b9d01e 100644 --- a/docs/reference/addleft.html +++ b/docs/reference/addleft.html @@ -1,75 +1,12 @@ - - - - - - - -Add Elements to the Left of Deques — addleft • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Add Elements to the Left of Deques — addleft • container - - + + - - -
-
- -
- -
+
-

Add elements to left side of Deque objects.

+

Add elements to left side of Deque objects.

-
addleft(.x, ...)
-
-ref_addleft(.x, ...)
+    
+
addleft(.x, ...)
+
+ref_addleft(.x, ...)
+
+# S3 method for Deque
+addleft(.x, ...)
+
+# S3 method for Deque
+ref_addleft(.x, ...)
+
-# S3 method for Deque -addleft(.x, ...) +
+

Arguments

+
.x
+

a [Deque] object

-# S3 method for Deque -ref_addleft(.x, ...)
-

Arguments

- - - - - - - - - - -
.x

a [Deque] object

...

elements to be added.

+
...
+

elements to be added.

-

Value

+
+
+

Value

+ -

For Deque, an object of class Deque with the elements being +

For Deque, an object of class Deque with the elements being added to the left of .x.

-

Note

- +
+
+

Note

While addleft uses copy semantics ref_addleft work by reference.

+
-

Examples

-
d = deque(0) -add(d, a = 1, b = 2) # |0, a = 1, b = 2| -
#> |0, a = 1, b = 2|
addleft(d, a = 1, b = 2) # |b = 2, a = 1, 0| -
#> |b = 2, a = 1, 0|
+
+

Examples

+
d = deque(0)
+add(d, a = 1, b = 2)         # |0, a = 1, b = 2|
+#> |0, a = 1, b = 2|
+addleft(d, a = 1, b = 2)     # |b = 2, a = 1, 0|
+#> |b = 2, a = 1, 0|
+
+
+
- - - + + diff --git a/docs/reference/at.html b/docs/reference/at.html index 8a763097..b863e1be 100644 --- a/docs/reference/at.html +++ b/docs/reference/at.html @@ -1,79 +1,16 @@ - - - - - - - -Extract Elements Safely — at • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Extract Elements Safely — at • container - - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -209,101 +135,111 @@

Extract Elements Safely

numbers, or both at the same time.

-
at(.x, ...)
+    
+
at(.x, ...)
+
+# S3 method for Container
+at(.x, ...)
+
+# S3 method for dict.table
+at(.x, ...)
+
-# S3 method for Container -at(.x, ...) +
+

Arguments

+
.x
+

an R object of the respective class.

-# S3 method for dict.table -at(.x, ...)
-

Arguments

- - - - - - - - - - -
.x

an R object of the respective class.

...

indices of elements to be extracted

+
...
+

indices of elements to be extracted

-

Value

+
+
+

Value

+ -

For Container, returns the values at the given indidces.

-

For dict.table, returns the columns at the given indices.

-

See also

+

For Container, returns the values at the given indidces.

-

peek_at() for less strict extraction

-

Examples

-
-# Container -co = container(a = 1, 2, b = 3, 4) -at(co, 1:3) -
#> [a = 1, 2, b = 3]
at(co, "a", "b", 2) -
#> [a = 1, b = 3, 2]
if (FALSE) { -at(co, "x") # index 'x' not found -at(co, 1:10) # index 5 exceeds length of Container -} -# Dict -d = dict(a = 1, b = 3) -at(d, 1:2) -
#> {a = 1, b = 3}
at(d, "a", 2) -
#> {a = 1, b = 3}
if (FALSE) { -at(d, "x") # index 'x' not found -at(d, 1:3) # index 5 exceeds length of Dict -} +

For dict.table, returns the columns at the given indices.

+
+
+

See also

+

peek_at() for less strict extraction

+
-# dict.table -dit = dict.table(a = 1:3, b = 4:6) -at(dit, "a") -
#> <dict.table> with 3 rows and 1 column -#> a -#> 1: 1 -#> 2: 2 -#> 3: 3
at(dit, 2) -
#> <dict.table> with 3 rows and 1 column -#> b -#> 1: 4 -#> 2: 5 -#> 3: 6
at(dit, "a", 2) -
#> <dict.table> with 3 rows and 2 columns -#> a b -#> 1: 1 4 -#> 2: 2 5 -#> 3: 3 6
if (FALSE) { -at(dit, "x") # index 'x' not found -at(dit, 1:3) # index 3 exceeds length of dict.table -} -
+
+

Examples

+

+# Container
+co = container(a = 1, 2, b = 3, 4)
+at(co, 1:3)
+#> [a = 1, 2, b = 3]
+at(co, "a", "b", 2)
+#> [a = 1, b = 3, 2]
+try(at(co, "x"))     # index 'x' not found
+#> Error : index 'x' not found
+try(at(co, 1:10))    # index 5 exceeds length of Container
+#> Error : index 5 exceeds length of Container, which is 4
+# Dict
+d = dict(a = 1, b = 3)
+at(d, 1:2)
+#> {a = 1, b = 3}
+at(d, "a", 2)
+#> {a = 1, b = 3}
+try(at(d, "x"))      # index 'x' not found
+#> Error : index 'x' not found
+try(at(d, 1:3))      # index 5 exceeds length of Dict
+#> Error : index 3 exceeds length of Dict, which is 2
+
+# dict.table
+dit = dict.table(a = 1:3, b = 4:6)
+at(dit, "a")
+#> <dict.table> with 3 rows and 1 column
+#>    a
+#> 1: 1
+#> 2: 2
+#> 3: 3
+at(dit, 2)
+#> <dict.table> with 3 rows and 1 column
+#>    b
+#> 1: 4
+#> 2: 5
+#> 3: 6
+at(dit, "a", 2)
+#> <dict.table> with 3 rows and 2 columns
+#>    a b
+#> 1: 1 4
+#> 2: 2 5
+#> 3: 3 6
+try(at(dit, "x"))     # index 'x' not found
+#> Error : index 'x' not found
+try(at(dit, 1:3))     # index 3 exceeds length of dict.table
+#> Error : index 3 exceeds length of dict.table, which is 2
+
+
+
- - - + + diff --git a/docs/reference/at2.html b/docs/reference/at2.html index 92635149..5093e322 100644 --- a/docs/reference/at2.html +++ b/docs/reference/at2.html @@ -1,82 +1,19 @@ - - - - - - - -Extract Single Elements Safely — at2 • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Extract Single Elements Safely — at2 • container - - - - - - - - - - - + + - - - -
-
- -
- -
+
@@ -215,96 +141,109 @@

Extract Single Elements Safely

leftmost element) is returned.

-
at2(x, ...)
+    
+
at2(x, ...)
+
+# S3 method for Container
+at2(x, index, ...)
+
+# S3 method for dict.table
+at2(x, index, ...)
+
-# S3 method for Container -at2(x, index, ...) +
+

Arguments

+
x
+

an R object of the respective class.

-# S3 method for dict.table -at2(x, index, ...)
-

Arguments

- - - - - - - - - - - - - - -
x

an R object of the respective class.

...

other arguments passed to or from methods.

index

character name or numeric position of the sought value.

+
...
+

other arguments passed to or from methods.

-

Value

-

For Container, returns the value at the given index.

-

For dict.table, returns the column at the given index or signals -an error if not found.

-

See also

+
index
+

character name or numeric position of the sought value.

+ +
+
+

Value

+ + +

For Container, returns the value at the given index.

-

peek_at2() for less strict extraction

-

Examples

-
-# Container -co = container(a = 1, 2, b = 3, 4) -at2(co, 1) -
#> [1] 1
at2(co, "a") -
#> [1] 1
at2(co, 2) -
#> [1] 2
if (FALSE) { -at2(co, "x") # index 'x' not found -at2(co, 5) # index 5 exceeds length of Container -} -# Dict -d = dict(a = 1, b = 3) -at2(d, 1) -
#> [1] 1
at2(d, "a") -
#> [1] 1
at2(d, 2) -
#> [1] 3
if (FALSE) { -at2(d, "x") # index 'x' not found -at2(d, 5) # index 5 exceeds length of Dict -} +

For dict.table, returns the column at the given index or signals +an error if not found.

+
+
+

See also

+

peek_at2() for less strict extraction

+
-# dict.table -dit = dict.table(a = 1:3, b = 4:6) -at2(dit, 1) -
#> [1] 1 2 3
at2(dit, "a") -
#> [1] 1 2 3
at2(dit, 2) -
#> [1] 4 5 6
if (FALSE) { -at2(dit, "x") # index 'x' not found -at2(dit, 5) # index 5 exceeds length of dict.table -} -
+
+

Examples

+

+# Container
+co = container(a = 1, 2, b = 3, 4)
+at2(co, 1)
+#> [1] 1
+at2(co, "a")
+#> [1] 1
+at2(co, 2)
+#> [1] 2
+try(at2(co, "x"))     # index 'x' not found
+#> Error : index 'x' not found
+try(at2(co, 5))       # index 5 exceeds length of Container
+#> Error : index 5 exceeds length of Container, which is 4
+
+# Dict
+d = dict(a = 1, b = 3)
+at2(d, 1)
+#> [1] 1
+at2(d, "a")
+#> [1] 1
+at2(d, 2)
+#> [1] 3
+try(at2(d, "x"))     # index 'x' not found
+#> Error : index 'x' not found
+try(at2(d, 5))       # index 5 exceeds length of Dict
+#> Error : index 5 exceeds length of Dict, which is 2
+
+# dict.table
+dit = dict.table(a = 1:3, b = 4:6)
+at2(dit, 1)
+#> [1] 1 2 3
+at2(dit, "a")
+#> [1] 1 2 3
+at2(dit, 2)
+#> [1] 4 5 6
+try(at2(dit, "x"))     # index 'x' not found
+#> Error : index 'x' not found
+try(at2(dit, 5))       # index 5 exceeds length of dict.table
+#> Error : index 5 exceeds length of dict.table, which is 2
+
+
+
- - - + + diff --git a/docs/reference/clear.html b/docs/reference/clear.html index 0f808cf0..f1d23cde 100644 --- a/docs/reference/clear.html +++ b/docs/reference/clear.html @@ -1,75 +1,12 @@ - - - - - - - -Clear a Container — clear • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Clear a Container — clear • container + + - - - - -
-
- -
- -
+
@@ -201,81 +127,89 @@

Clear a Container

Removes all elements from the container object.

-
clear(x)
-
-ref_clear(x)
-
-# S3 method for Container
-clear(x)
-
-# S3 method for Container
-ref_clear(x)
+    
+
clear(x)
+
+ref_clear(x)
+
+# S3 method for Container
+clear(x)
+
+# S3 method for Container
+ref_clear(x)
+
+# S3 method for dict.table
+clear(x)
+
+# S3 method for dict.table
+ref_clear(x)
+
-# S3 method for dict.table -clear(x) +
+

Arguments

+
x
+

any R object.

-# S3 method for dict.table -ref_clear(x)
+
+
+

Value

+ -

Arguments

- - - - - - -
x

any R object.

+

For Container, an object of class Container (or one of the +respective derived classes).

-

Value

-

For Container, an object of class Container (or one of the -respective derived classes).

-

For dict.table an object of class -dict.table.

+

For dict.table an object of class +dict.table.

+
-

Examples

-
-co = container(1, 2, mean) -clear(co) -
#> []
co -
#> [1, 2, <<function>>]
ref_clear(co) -co -
#> []
-dit = dict.table(a = 1, b = 2) -clear(dit) -
#> <dict.table> with 0 rows and 0 columns -#> Null data.table (0 rows and 0 cols)
dit # original was not touched -
#> <dict.table> with 1 row and 2 columns -#> a b -#> 1: 1 2
ref_clear(dit) -dit # original was cleared -
#> <dict.table> with 0 rows and 0 columns -#> Null data.table (0 rows and 0 cols)
+
+

Examples

+

+co = container(1, 2, mean)
+clear(co)
+#> []
+co
+#> [1, 2, <<function>>]
+ref_clear(co)
+co
+#> []
+
+dit = dict.table(a = 1, b = 2)
+clear(dit)
+#> <dict.table> with 0 rows and 0 columns
+#> Null data.table (0 rows and 0 cols)
+dit              # original was not touched
+#> <dict.table> with 1 row and 2 columns
+#>    a b
+#> 1: 1 2
+ref_clear(dit)
+dit              # original was cleared
+#> <dict.table> with 0 rows and 0 columns
+#> Null data.table (0 rows and 0 cols)
+
+
+
- - - + + diff --git a/docs/reference/clone.html b/docs/reference/clone.html index 78b357d2..0c33b9e3 100644 --- a/docs/reference/clone.html +++ b/docs/reference/clone.html @@ -1,75 +1,12 @@ - - - - - - - -Clone an Object — clone • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Clone an Object — clone • container - - + + - - -
-
- -
- -
+
@@ -201,66 +127,68 @@

Clone an Object

Creates a copy of the object.

-
clone(x)
-
-# S3 method for Container
-clone(x)
-
-# S3 method for dict.table
-clone(x)
+
+
clone(x)
+
+# S3 method for Container
+clone(x)
+
+# S3 method for dict.table
+clone(x)
+
-

Arguments

- - - - - - -
x

any R object.

+
+

Arguments

+
x
+

any R object.

-

Value

+
+
+

Value

+ -

A copy of the object.

+

A copy of the object.

+
-

Examples

-
-co = container(1, 2, 3) -co2 = clone(co) -co == co2 -
#> [1] TRUE
-d = dict.table(a = 1:2, b = 3:4) -d2 = clone(d) -ref_clear(d) -print(d2) -
#> <dict.table> with 2 rows and 2 columns -#> a b -#> 1: 1 3 -#> 2: 2 4
+
+

Examples

+

+co = container(1, 2, 3)
+co2 = clone(co)
+co == co2
+#> [1] TRUE
+
+d = dict.table(a = 1:2, b = 3:4)
+d2 = clone(d)
+ref_clear(d)
+print(d2)
+#> <dict.table> with 2 rows and 2 columns
+#>    a b
+#> 1: 1 3
+#> 2: 2 4
+
+
+
- - - + + diff --git a/docs/reference/container_options.html b/docs/reference/container_options.html index cab086d3..291935a1 100644 --- a/docs/reference/container_options.html +++ b/docs/reference/container_options.html @@ -1,75 +1,12 @@ - - - - - - - -Set Container Package Options — container_options • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Set Container Package Options — container_options • container - - - - + + -
-
- -
- -
+
@@ -201,122 +127,125 @@

Set Container Package Options

Set Container Package Options

-
container_options(..., .reset = FALSE)
+    
+
container_options(..., .reset = FALSE)
+
+getContainerOption(x, default = NULL)
+
+ +
+

Arguments

+
...
+

any options can be defined, using name = value.

+ + +
.reset
+

logical if TRUE, the options are reset to their default and +returned.

-getContainerOption(x, default = NULL)
-

Arguments

- - - - - - - - - - - - - - - - - - -
...

any options can be defined, using name = value.

.reset

logical if TRUE, the options are reset to their default and -returned.

x

a character string holding an option name.

default

if the specified option is not set in the options list, this -value is returned.

+
x
+

a character string holding an option name.

-

Value

+
default
+

if the specified option is not set in the options list, this +value is returned.

+ +
+
+

Value

-
    -
  • container_options() returns a list of all set options sorted by name.

  • + +
    • container_options() returns a list of all set options sorted by name.

    • container_options(name), a list of length one containing the set value, or NULL if it is unset. Can also be multiple names (see Examples).

    • container_options(key = value) sets the option with name key to value and returns the previous options invisibly.

    • -
    - -

    Container Options

    - +
+
+

Container Options

-
    -
  • compare (default = all.equal)

  • +
    • compare (default = all.equal)

    • useDots (default = TRUE) whether to abbreviate long container elements with ... when exceeding vec.len (see below). If FALSE, they are abbreviated as <<type(length)>>.

    • vec.len (default = 4) the length limit at which container vectors are abbreviated.

    • -
    - - -

    Examples

    -
    co = container(1L, 1:10, as.list(1:5)) -co -
    #> [1L, (1L 2L 3L 4L ...), <<list(5)>>]
    -container_options(useDots = FALSE) -co -
    #> [1L, <<integer(10)>>, <<list(5)>>]
    -container_options(useDots = TRUE, vec.len = 6) -co -
    #> [1L, (1L 2L 3L 4L 5L 6L ...), list(1L, 2L, 3L, 4L, 5L)]
    -has(co, 1.0) -
    #> [1] TRUE
    -container_options(compare = "identical") - -has(co, 1.0) # still uses 'all.equal' -
    #> [1] TRUE
    -co2 = container(1L) -has(co2, 1.0) -
    #> [1] FALSE
    has(co2, 1L) -
    #> [1] TRUE
    -container_options() -
    #> $compare -#> [1] "identical" -#> -#> $useDots -#> [1] TRUE -#> -#> $vec.len -#> [1] 6 -#>
    container_options(.reset = TRUE) -
    #> $compare -#> [1] "all.equal" -#> -#> $useDots -#> [1] TRUE -#> -#> $vec.len -#> [1] 4 -#>
    +
+ +
+

Examples

+
co = container(1L, 1:10, as.list(1:5))
+co
+#> [1L, (1L 2L 3L 4L ...), <<list(5)>>]
+
+container_options(useDots = FALSE)
+co
+#> [1L, <<integer(10)>>, <<list(5)>>]
+
+container_options(useDots = TRUE, vec.len = 6)
+co
+#> [1L, (1L 2L 3L 4L 5L 6L ...), list(1L, 2L, 3L, 4L, 5L)]
+
+has(co, 1.0)
+#> [1] TRUE
+
+container_options(compare = "identical")
+
+has(co, 1.0) # still uses 'all.equal'
+#> [1] TRUE
+
+co2 = container(1L)
+has(co2, 1.0)
+#> [1] FALSE
+has(co2, 1L)
+#> [1] TRUE
+
+container_options()
+#> $compare
+#> [1] "identical"
+#> 
+#> $useDots
+#> [1] TRUE
+#> 
+#> $vec.len
+#> [1] 6
+#> 
+container_options(.reset = TRUE)
+#> $compare
+#> [1] "all.equal"
+#> 
+#> $useDots
+#> [1] TRUE
+#> 
+#> $vec.len
+#> [1] 4
+#> 
+
+
+
- - - + + diff --git a/docs/reference/count.html b/docs/reference/count.html index 409a84be..24301efe 100644 --- a/docs/reference/count.html +++ b/docs/reference/count.html @@ -1,75 +1,12 @@ - - - - - - - -Count Elements — count • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Count Elements — count • container - - + + - - -
-
- -
- -
+
@@ -201,63 +127,66 @@

Count Elements

Count the number of occurences of some element.

-
count(x, elem)
+    
+
count(x, elem)
+
+# S3 method for Container
+count(x, elem)
+
+# S3 method for Set
+count(x, elem)
+
-# S3 method for Container -count(x, elem) +
+

Arguments

+
x
+

any R object.

-# S3 method for Set -count(x, elem)
-

Arguments

- - - - - - - - - - -
x

any R object.

elem

element to counted.

+
elem
+

element to counted.

-

Value

+
+
+

Value

+ -

integer number of how many times elem occurs in the object.

+

integer number of how many times elem occurs in the object.

+
-

Examples

-
-co = container("a", "b", "a", mean, mean) -count(co, "a") -
#> [1] 2
count(co, mean) -
#> [1] 2
count(co, "c") -
#> [1] 0
+
+

Examples

+

+co = container("a", "b", "a", mean, mean)
+count(co, "a")
+#> [1] 2
+count(co, mean)
+#> [1] 2
+count(co, "c")
+#> [1] 0
+
+
+
- - - + + diff --git a/docs/reference/delete.html b/docs/reference/delete.html index a7aa0ee3..df5b4e0f 100644 --- a/docs/reference/delete.html +++ b/docs/reference/delete.html @@ -1,76 +1,13 @@ - - - - - - - -Delete Container Elements Safely — delete • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Delete Container Elements Safely — delete • container - - - - + + -
-
- -
- -
+
@@ -203,69 +129,73 @@

Delete Container Elements Safely

an error is signaled.

-
delete(.x, ...)
-
-ref_delete(.x, ...)
+    
+
delete(.x, ...)
+
+ref_delete(.x, ...)
+
+# S3 method for Container
+delete(.x, ...)
+
+# S3 method for Container
+ref_delete(.x, ...)
+
-# S3 method for Container -delete(.x, ...) +
+

Arguments

+
.x
+

any R object.

-# S3 method for Container -ref_delete(.x, ...)
-

Arguments

- - - - - - - - - - -
.x

any R object.

...

elements to be deleted.

+
...
+

elements to be deleted.

-

Value

+
+
+

Value

+ -

For Container, an object of class Container (or one of the +

For Container, an object of class Container (or one of the respective derived classes).

+
-

Examples

-
-s = setnew("a", 1:3, iris) -print(s) -
#> {"a", (1L 2L 3L), <<data.frame(150x5)>>}
delete(s, 1:3, "a") -
#> {<<data.frame(150x5)>>}
delete(s, iris) -
#> {"a", (1L 2L 3L)}
if (FALSE) { -delete(s, "b") # "b" is not in Set -} -
+
+

Examples

+

+s = setnew("a", 1:3, iris)
+print(s)
+#> {"a", (1L 2L 3L), <<data.frame(150x5)>>}
+delete(s, 1:3, "a")
+#> {<<data.frame(150x5)>>}
+delete(s, iris)
+#> {"a", (1L 2L 3L)}
+try({
+delete(s, "b")  # "b" is not in Set
+})
+#> Error : "b" is not in Set
+
+
+
- - - + + diff --git a/docs/reference/delete_at.html b/docs/reference/delete_at.html index add73323..9c21641f 100644 --- a/docs/reference/delete_at.html +++ b/docs/reference/delete_at.html @@ -1,77 +1,14 @@ - - - - - - - -Delete Elements at Indices Safely — delete_at • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Delete Elements at Indices Safely — delete_at • container - - - - - - - - - - + + - - - - -
-
- -
- -
+
@@ -205,106 +131,116 @@

Delete Elements at Indices Safely

numbers or names or both.

-
delete_at(.x, ...)
-
-ref_delete_at(.x, ...)
+    
+
delete_at(.x, ...)
+
+ref_delete_at(.x, ...)
+
+# S3 method for Container
+delete_at(.x, ...)
+
+# S3 method for Container
+ref_delete_at(.x, ...)
+
+# S3 method for dict.table
+delete_at(.x, ...)
+
+# S3 method for dict.table
+ref_delete_at(.x, ...)
+
-# S3 method for Container -delete_at(.x, ...) +
+

Arguments

+
.x
+

any R object.

-# S3 method for Container -ref_delete_at(.x, ...) -# S3 method for dict.table -delete_at(.x, ...) +
...
+

indices at which values are to be deleted.

-# S3 method for dict.table -ref_delete_at(.x, ...)
+
+
+

Value

+ -

Arguments

- - - - - - - - - - -
.x

any R object.

...

indices at which values are to be deleted.

+

For Container, an object of class Container (or one of the +respective derived classes).

-

Value

-

For Container, an object of class Container (or one of the -respective derived classes).

For dict.table, an object of class dict.table.

+
-

Examples

-
-co = container(a = 1, b = 2, 3) -delete_at(co, "a", "b") # [3] -
#> [3]
delete_at(co, 1:2) # [3] -
#> [3]
delete_at(co, "a", 3) # [b = 2] -
#> [b = 2]
if (FALSE) { -delete_at(co, 4) # index out of range -delete_at(co, "x") # names(s) not found: 'x' -} - -dit = as.dict.table(head(sleep)) -dit -
#> <dict.table> with 6 rows and 3 columns -#> extra group ID -#> 1: 0.7 1 1 -#> 2: -1.6 1 2 -#> 3: -0.2 1 3 -#> 4: -1.2 1 4 -#> 5: -0.1 1 5 -#> 6: 3.4 1 6
delete_at(dit, "ID") -
#> <dict.table> with 6 rows and 2 columns -#> extra group -#> 1: 0.7 1 -#> 2: -1.6 1 -#> 3: -0.2 1 -#> 4: -1.2 1 -#> 5: -0.1 1 -#> 6: 3.4 1
delete_at(dit, "ID", 1) -
#> <dict.table> with 6 rows and 1 column -#> group -#> 1: 1 -#> 2: 1 -#> 3: 1 -#> 4: 1 -#> 5: 1 -#> 6: 1
if (FALSE) { -delete_at(dit, "foo") # Column 'foo' not in dict.table -} -
+
+

Examples

+

+co = container(a = 1, b = 2, 3)
+delete_at(co, "a", "b")          # [3]
+#> [3]
+delete_at(co, 1:2)               # [3]
+#> [3]
+delete_at(co, "a", 3)            # [b = 2]
+#> [b = 2]
+try({
+delete_at(co, 4)                 # index out of range
+delete_at(co, "x")               # names(s) not found: 'x'
+})
+#> Error : index out of range (length = 3): 4
+
+dit = as.dict.table(head(sleep))
+dit
+#> <dict.table> with 6 rows and 3 columns
+#>    extra group ID
+#> 1:   0.7     1  1
+#> 2:  -1.6     1  2
+#> 3:  -0.2     1  3
+#> 4:  -1.2     1  4
+#> 5:  -0.1     1  5
+#> 6:   3.4     1  6
+delete_at(dit, "ID")
+#> <dict.table> with 6 rows and 2 columns
+#>    extra group
+#> 1:   0.7     1
+#> 2:  -1.6     1
+#> 3:  -0.2     1
+#> 4:  -1.2     1
+#> 5:  -0.1     1
+#> 6:   3.4     1
+delete_at(dit, "ID", 1)
+#> <dict.table> with 6 rows and 1 column
+#>    group
+#> 1:     1
+#> 2:     1
+#> 3:     1
+#> 4:     1
+#> 5:     1
+#> 6:     1
+try({
+ delete_at(dit, "foo")   # Column 'foo' not in dict.table
+})
+#> Error : column(s) not found: 'foo'
+
+
+
- - - + + diff --git a/docs/reference/deprecated.html b/docs/reference/deprecated.html index 9b9aa7ec..4ccae484 100644 --- a/docs/reference/deprecated.html +++ b/docs/reference/deprecated.html @@ -1,76 +1,13 @@ - - - - - - - -Deprecated Functions — deprecated • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Deprecated Functions — deprecated • container - - - - + + -
-
- -
- -
+
@@ -203,83 +129,76 @@

Deprecated Functions

may be defunct as soon as the next release.

-
empty(x)
-
-# S3 method for Container
-empty(x)
-
-size(x)
-
-# S3 method for Container
-size(x)
-
-sortkey(x, decr = FALSE)
-
-# S3 method for Dict
-sortkey(x, decr = FALSE)
-
-values(x)
-
-# S3 method for Container
-values(x)
-
-# S3 method for dict.table
-values(x)
+    
+
empty(x)
+
+# S3 method for Container
+empty(x)
+
+size(x)
+
+# S3 method for Container
+size(x)
+
+sortkey(x, decr = FALSE)
+
+# S3 method for Dict
+sortkey(x, decr = FALSE)
+
+values(x)
+
+# S3 method for Container
+values(x)
+
+# S3 method for dict.table
+values(x)
+
+keys(x)
+
-keys(x)
+
+

Arguments

+
x
+

any R object.

-

Arguments

- - - - - - - - - - -
x

any R object.

decr

logical sort decreasingly?

-

Details

+
decr
+

logical sort decreasingly?

+
+
+

Details

- - +
+
- - - + + diff --git a/docs/reference/dequeS3.html b/docs/reference/dequeS3.html index cf4b41ab..f1f64551 100644 --- a/docs/reference/dequeS3.html +++ b/docs/reference/dequeS3.html @@ -1,78 +1,15 @@ - - - - - - - -Deque - Double-Ended Queue — DequeS3 • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Deque - Double-Ended Queue — DequeS3 • container - - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -207,193 +133,205 @@

Deque - Double-Ended Queue

both stacks and queues.

-
deque(...)
-
-as.deque(x)
+    
+
deque(...)
+
+as.deque(x)
+
+is.deque(x)
+
-is.deque(x)
+
+

Arguments

+
...
+

initial elements put into the Deque.

-

Arguments

- - - - - - - - - - -
...

initial elements put into the Deque.

x

R object of ANY type for as.deque() and is.deque() -or of class Deque for the S3 methods.

-

Details

+
x
+

R object of ANY type for as.deque() and is.deque() +or of class Deque for the S3 methods.

-

Methods that alter Deque objects usually come in two versions +

+
+

Details

+

Methods that alter Deque objects usually come in two versions providing either copy or reference semantics where the latter start with -'ref_' to note the reference semantic, for example, add() and ref_add().

-
    -
  • deque(...) initializes and returns an object of class Deque

  • -
- -
    -
  • as.deque(x) coerces x to a deque.

  • -
- -
    -
  • is.deque(x) returns TRUE if x is of class Deque +'ref_' to note the reference semantic, for example, add() and ref_add().

    +
    • deque(...) initializes and returns an object of class Deque

    • +
    • as.deque(x) coerces x to a deque.

    • +
    • is.deque(x) returns TRUE if x is of class Deque and FALSE otherwise.

    • -
    - -
      -
    • x + y combines x and y into a new deque by appending y +

    • x + y combines x and y into a new deque by appending y to x.

    • -
    - -
      -
    • x - y element-wise removes all items of y from x, given +

    • x - y element-wise removes all items of y from x, given the element was contained in x.

    • -
    - - - -
    • addleft(.x, ...) adds (possibly named) elements to left side of .x.

    • +
    • ref_addleft(.x, ...) same as addleft(.x, ...) but adds by reference.

    • +
    • peek(x, default = NULL) peek at last element. If x is empty, return default.

    • -
    • peekleft(x, default = NULL) peek at first element. If x is empty, +

    • peekleft(x, default = NULL) peek at first element. If x is empty, return default.

    • -
    - -
      -
    • ref_pop(.x) pop last element. If .x is empty, an error is given.

    • -
    • ref_popleft(.x) pop first element. If .x is empty, an error is given.

    • -
    - -
    • ref_pop(.x) pop last element. If .x is empty, an error is given.

    • +
    • ref_popleft(.x) pop first element. If .x is empty, an error is given.

    • +
    • rev(x) and ref_rev(x) reverses all elements being done on a copy or in place, respectively.

    • -
    - -
      -
    • rotate(x, n) rotate all elements n steps to the right, If n is +

    • rotate(x, n) rotate all elements n steps to the right, If n is negative, rotate to the left.

    • -
    - -

    See also

    - -

    See container() for all inherited methods. For the full class -documentation see Deque() and it's superclass Container().

    - -

    Examples

    -
    d = deque(1, 2, s = "a", v = 1:3) -is.deque(d) -
    #> [1] TRUE
    print(d) -
    #> |1, 2, s = "a", v = (1L 2L 3L)|
    length(d) -
    #> [1] 4
    names(d) -
    #> [1] "" "" "s" "v"
    as.list(d) -
    #> [[1]] -#> [1] 1 -#> -#> [[2]] -#> [1] 2 -#> -#> $s -#> [1] "a" -#> -#> $v -#> [1] 1 2 3 -#>
    rev(d) -
    #> |v = (1L 2L 3L), s = "a", 2, 1|
    -l = list(0, 1) -d2 = as.deque(l) -d + d2 -
    #> |1, 2, s = "a", v = (1L 2L 3L), 0, 1|
    c(d, d2) # same as d + d2 -
    #> |1, 2, s = "a", v = (1L 2L 3L), 0, 1|
    d2 + d -
    #> |0, 1, 1, 2, s = "a", v = (1L 2L 3L)|
    d - d2 -
    #> |2, s = "a", v = (1L 2L 3L)|
    c(d2, d) # same as d2 + d -
    #> |0, 1, 1, 2, s = "a", v = (1L 2L 3L)|
    d2 - d -
    #> |0|
    # Math -d = deque(1, 2, -(3:5)) -d -
    #> |1, 2, (-3L -4L -5L)|
    abs(d) -
    #> |1, 2, 3, 4, 5|
    cumsum(d) -
    #> |1, 3, 0, -4, -9|
    round(d) -
    #> |1, 2, -3, -4, -5|
    exp(d) -
    #> |2.718282, 7.389056, 0.04978707, 0.01831564, 0.006737947|
    -# Summary -range(d) -
    #> [1] -5 2
    min(d) -
    #> [1] -5
    max(d) -
    #> [1] 2
    -d1 = deque(1, 1:2) -d2 = deque(2, 1:2) -d1 + d2 # same as c(d1, d2) -
    #> |1, (1L 2L), 2, (1L 2L)|
    d2 + d1 # same as c(d2, d1) -
    #> |2, (1L 2L), 1, (1L 2L)|
    -d1 - d2 -
    #> |1|
    d2 - d1 -
    #> |2|
    d1 - d1 -
    #> ||
    - -d = deque(0) -add(d, a = 1, b = 2) # |0, a = 1, b = 2| -
    #> |0, a = 1, b = 2|
    addleft(d, a = 1, b = 2) # |b = 2, a = 1, 0| -
    #> |b = 2, a = 1, 0|
    -d = deque(1, 2, 3) -peek(d) -
    #> [1] 3
    #> [1] 1
    peek(deque()) -
    #> NULL
    peek(deque(), default = 0) -
    #> [1] 0
    peekleft(deque(), default = 0) -
    #> [1] 0
    d = deque(1, 2, 3) -ref_pop(d) -
    #> [1] 3
    print(d) -
    #> |1, 2|
    #> [1] 1
    print(d) -
    #> |2|
    -if (FALSE) { -ref_pop(deque()) # pop at empty Deque -} +
+
+

See also

+

See container() for all inherited methods. For the full class +documentation see Deque() and it's superclass Container().

+
-d = deque(a = 1, b = 2, 3) -rev(d) -
#> |3, b = 2, a = 1|
print(d) -
#> |a = 1, b = 2, 3|
ref_rev(d) -
#> |3, b = 2, a = 1|
print(d) -
#> |3, b = 2, a = 1|
-d = deque(1, 2, 3, 4) -rotate(d) -
#> |4, 1, 2, 3|
rotate(d, n = 2) -
#> |3, 4, 1, 2|
-
+
+

Examples

+
d = deque(1, 2, s = "a", v = 1:3)
+is.deque(d)
+#> [1] TRUE
+print(d)
+#> |1, 2, s = "a", v = (1L 2L 3L)|
+length(d)
+#> [1] 4
+names(d)
+#> [1] ""  ""  "s" "v"
+as.list(d)
+#> [[1]]
+#> [1] 1
+#> 
+#> [[2]]
+#> [1] 2
+#> 
+#> $s
+#> [1] "a"
+#> 
+#> $v
+#> [1] 1 2 3
+#> 
+rev(d)
+#> |v = (1L 2L 3L), s = "a", 2, 1|
+
+l = list(0, 1)
+d2 = as.deque(l)
+d + d2
+#> |1, 2, s = "a", v = (1L 2L 3L), 0, 1|
+c(d, d2) # same as d + d2
+#> |1, 2, s = "a", v = (1L 2L 3L), 0, 1|
+d2 + d
+#> |0, 1, 1, 2, s = "a", v = (1L 2L 3L)|
+d - d2
+#> |2, s = "a", v = (1L 2L 3L)|
+c(d2, d) # same as d2 + d
+#> |0, 1, 1, 2, s = "a", v = (1L 2L 3L)|
+d2 - d
+#> |0|
+# Math
+d = deque(1, 2, -(3:5))
+d
+#> |1, 2, (-3L -4L -5L)|
+abs(d)
+#> |1, 2, 3, 4, 5|
+cumsum(d)
+#> |1, 3, 0, -4, -9|
+round(d)
+#> |1, 2, -3, -4, -5|
+exp(d)
+#> |2.718282, 7.389056, 0.04978707, 0.01831564, 0.006737947|
+
+# Summary
+range(d)
+#> [1] -5  2
+min(d)
+#> [1] -5
+max(d)
+#> [1] 2
+
+d1 = deque(1, 1:2)
+d2 = deque(2, 1:2)
+d1 + d2     # same as c(d1, d2)
+#> |1, (1L 2L), 2, (1L 2L)|
+d2 + d1     # same as c(d2, d1)
+#> |2, (1L 2L), 1, (1L 2L)|
+
+d1 - d2
+#> |1|
+d2 - d1
+#> |2|
+d1 - d1
+#> ||
+
+
+d = deque(0)
+add(d, a = 1, b = 2)         # |0, a = 1, b = 2|
+#> |0, a = 1, b = 2|
+addleft(d, a = 1, b = 2)     # |b = 2, a = 1, 0|
+#> |b = 2, a = 1, 0|
+
+d = deque(1, 2, 3)
+peek(d)
+#> [1] 3
+peekleft(d)
+#> [1] 1
+peek(deque())
+#> NULL
+peek(deque(), default = 0)
+#> [1] 0
+peekleft(deque(), default = 0)
+#> [1] 0
+d = deque(1, 2, 3)
+ref_pop(d)
+#> [1] 3
+print(d)
+#> |1, 2|
+ref_popleft(d)
+#> [1] 1
+print(d)
+#> |2|
+
+try({
+ref_pop(deque())  # pop at empty Deque
+})
+#> Error : pop at empty Deque
+
+d = deque(a = 1, b = 2, 3)
+rev(d)
+#> |3, b = 2, a = 1|
+print(d)
+#> |a = 1, b = 2, 3|
+ref_rev(d)
+#> |3, b = 2, a = 1|
+print(d)
+#> |3, b = 2, a = 1|
+
+d = deque(1, 2, 3, 4)
+rotate(d)
+#> |4, 1, 2, 3|
+rotate(d, n = 2)
+#> |3, 4, 1, 2|
+
+
+
+
- - - + + diff --git a/docs/reference/dict.table.html b/docs/reference/dict.table.html index 1f17a817..2fb070e6 100644 --- a/docs/reference/dict.table.html +++ b/docs/reference/dict.table.html @@ -1,53 +1,5 @@ - - - - - - - -Combining Dict and data.table — dict.table • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Combining Dict and data.table — dict.table • container - - - - - - - - - - - + + - - - -
-
- -
- -
+
-

The dict.table is a combination of dict and -data.table +

The dict.table is a combination of dict and +data.table and basically can be considered a -data.table +data.table with unique column names and an extended set of functions to add, extract and remove data columns with the goal to further facilitate code development -using data.table. -A dict.table object provides all dict and -data.table +using data.table. +A dict.table object provides all dict and +data.table functions and operators at the same time.

-
dict.table(...)
-
-as.dict.table(x, ...)
-
-# S3 method for data.table
-as.dict.table(x, copy = TRUE, ...)
+    
+
dict.table(...)
+
+as.dict.table(x, ...)
+
+# S3 method for data.table
+as.dict.table(x, copy = TRUE, ...)
+
+is.dict.table(x)
+
+# S3 method for dict.table
+rbind(x, ...)
+
+# S3 method for dict.table
+cbind(x, ...)
+
-is.dict.table(x) +
+

Arguments

+
...
+

elements put into the dict.table and/or additional +arguments to be passed on.

-# S3 method for dict.table -rbind(x, ...) -# S3 method for dict.table -cbind(x, ...)
+
x
+

any R object or a dict.table object.

-

Arguments

- - - - - - - - - - - - - - -
...

elements put into the dict.table and/or additional -arguments to be passed on.

x

any R object or a dict.table object.

copy

if TRUE creates a copy of the data.table object otherwise -works on the passed object by reference.

-

Details

+
copy
+

if TRUE creates a copy of the data.table object otherwise +works on the passed object by reference.

+
+
+

Details

Methods that alter dict.table objects usually come in two versions providing either copy or reference semantics where the latter start with -'ref_' to note the reference semantic, for example, add() and ref_add().

-
    -
  • dict.table(...) initializes and returns a dict object.

  • -
- -
    -
  • as.dict.table(x, ...) coerce x to a dict.table

  • -
- -
    -
  • is.dict.table(x) check if x is a dict.table

  • -
- -
    -
  • add(.x, ...) and ref_add(.x, ...) add columns to .x. If the column name +'ref_' to note the reference semantic, for example, add() and ref_add().

    +
    • dict.table(...) initializes and returns a dict object.

    • +
    • as.dict.table(x, ...) coerce x to a dict.table

    • +
    • is.dict.table(x) check if x is a dict.table

    • +
    • add(.x, ...) and ref_add(.x, ...) add columns to .x. If the column name already exists, an error is given.

    • -
    - -
      -
    • at(.x, ...) returns the columns at the given indices. Indices +

    • at(.x, ...) returns the columns at the given indices. Indices can be letters or numbers or both. All columns must exist.

    • -
    - -
      -
    • at2(x, index) returns the column at the given index or signals +

    • at2(x, index) returns the column at the given index or signals an error if not found.

    • -
    - - - - - -
    • clear(x) and ref_clear(x) remove all elements from x.

    • +
    • clone(x) create a copy of x.

    • +
    • delete_at(.x, ...) and ref_delete_at(.x, ...) find and remove columns either by name or index (or both). If one or more columns don't exist, an error is signaled.

    • -
    - -
    • discard_at(.x, ...) and ref_discard_at(.x, ...) find and remove columns either by name or index (or both). Invalid column indices are ignored.

    • -
    - - - - - -
      -
    • is_empty(x) TRUE if object is empty otherwise FALSE

    • -
    - -
    • has(x, column) check if some column is in dict.table object.

    • +
    • has_name(x, name) check if x has the given column name.

    • +
    • is_empty(x) TRUE if object is empty otherwise FALSE

    • +
    • peek_at(x, ..., .default = NULL) returns the columns at the given indices or (if not found) columns with the given default value.

    • -
    - -
    • peek_at2(x, index, default = NULL) return column named index if it exist otherwise the given default value. If the default length does not match the number of rows, it is recycled accordingly and a warning is given, unless the default value has a length of 1, in which case recycling is done silently.

    • -
    - -
    • ref_pop(.x, index) return element at given column index and remove the column from the dict.table object.

    • -
    - -
    • rename(.x, old, new) and ref_rename(.x, old, new) rename one or more columns from old to new, respectively, by copy and in place (i.e. by reference).

    • -
    - -
    • replace_at(.x, .., .add = FALSE) and ref_replace_at(.x, ..., .add = FALSE) replace values at given indices. If a given index is invalid, an error is signaled unless .add was set to TRUE.

    • -
    - -
    • update(object, other) and ref_update(object, other) adds columns of other dict that are not yet in object and replaces the values at existing columns.

    • -
    - -

    See also

    - - - -

    Examples

    -
    # Some basic examples using some typical data.table and dict operations. -# The constructor can take the 'key' argument known from data.table(): -require(data.table) -
    #> Loading required package: data.table
    dit = dict.table(x = rep(c("b","a","c"), each = 3), y = c(1,3,6), key = "y") -print(dit) -
    #> <dict.table> with 9 rows and 2 columns -#> x y -#> 1: b 1 -#> 2: a 1 -#> 3: c 1 -#> 4: b 3 -#> 5: a 3 -#> 6: c 3 -#> 7: b 6 -#> 8: a 6 -#> 9: c 6
    setkey(dit, "x") # sort by 'x' -print(dit) -
    #> <dict.table> with 9 rows and 2 columns -#> x y -#> 1: a 1 -#> 2: a 3 -#> 3: a 6 -#> 4: b 1 -#> 5: b 3 -#> 6: b 6 -#> 7: c 1 -#> 8: c 3 -#> 9: c 6
    (add(dit, "v" = 1:9)) # add column v = 1:9 -
    #> <dict.table> with 9 rows and 3 columns -#> x y v -#> 1: a 1 1 -#> 2: a 3 2 -#> 3: a 6 3 -#> 4: b 1 4 -#> 5: b 3 5 -#> 6: b 6 6 -#> 7: c 1 7 -#> 8: c 3 8 -#> 9: c 6 9
    dit[y > 5] -
    #> <dict.table> with 3 rows and 2 columns -#> x y -#> 1: a 6 -#> 2: b 6 -#> 3: c 6
    (ref_discard_at(dit, "x")) # discard column 'x' -
    #> <dict.table> with 9 rows and 1 column -#> y -#> 1: 1 -#> 2: 3 -#> 3: 6 -#> 4: 1 -#> 5: 3 -#> 6: 6 -#> 7: 1 -#> 8: 3 -#> 9: 6
    -if (FALSE) { -at(dit, "x") # index 'x' not found -replace_at(dit, x = 0) # cannot be replaced, if it does not exist -} - -dit = replace_at(dit, x = 0, .add = TRUE) # ok - re-adds column 'x' with all 0s -peek_at(dit, "x") # glance at column 'x' -
    #> <dict.table> with 9 rows and 1 column -#> x -#> 1: 0 -#> 2: 0 -#> 3: 0 -#> 4: 0 -#> 5: 0 -#> 6: 0 -#> 7: 0 -#> 8: 0 -#> 9: 0
    has_name(dit, "x") # TRUE -
    #> [1] TRUE
    ref_pop(dit, "x") # get column and remove it -
    #> [1] 0 0 0 0 0 0 0 0 0
    has_name(dit, "x") # FALSE -
    #> [1] FALSE
    - -# Copy and reference semantics when coercing *from* a data.table -dat = data.table(a = 1, b = 2) -dit = as.dict.table(dat) -is.dict.table(dit) # TRUE -
    #> [1] TRUE
    is.dict.table(dat) # FALSE -
    #> [1] FALSE
    ref_replace_at(dit, "a", 9) -dit[["a"]] # 9 -
    #> [1] 9
    dat[["a"]] # 1 -
    #> [1] 1
    dit.dat = as.dict.table(dat, copy = FALSE) # init by reference -ref_replace_at(dit.dat, "a", 9) -dat[["a"]] # 9 -
    #> [1] 9
    is.dict.table(dit.dat) # TRUE -
    #> [1] TRUE
    is.dict.table(dat) # TRUE now as well! -
    #> [1] TRUE
    -# Coerce from dict -d = dict(a = 1, b = 1:3) -as.dict.table(d) -
    #> <dict.table> with 3 rows and 2 columns -#> a b -#> 1: 1 1 -#> 2: 1 2 -#> 3: 1 3
    -dit = dict.table(a = 1:2, b = 1:2) -rbind(dit, dit) -
    #> <dict.table> with 4 rows and 2 columns -#> a b -#> 1: 1 1 -#> 2: 2 2 -#> 3: 1 1 -#> 4: 2 2
    -# rbind ... -dit = dict.table(a = 1:2, b = 1:2) -rbind(dit, dit) -
    #> <dict.table> with 4 rows and 2 columns -#> a b -#> 1: 1 1 -#> 2: 2 2 -#> 3: 1 1 -#> 4: 2 2
    -# ... can be mixed with data.tables -dat = data.table(a = 3:4, b = 3:4) -rbind(dit, dat) # yields a dict.table -
    #> <dict.table> with 4 rows and 2 columns -#> a b -#> 1: 1 1 -#> 2: 2 2 -#> 3: 3 3 -#> 4: 4 4
    rbind(dat, dit) # yields a data.table -
    #> a b -#> 1: 3 3 -#> 2: 4 4 -#> 3: 1 1 -#> 4: 2 2
    -# cbind ... -dit = dict.table(a = 1:2, b = 1:2) -dit2 = dict.table(c = 3:4, d = 5:6) -cbind(dit, dit2) -
    #> <dict.table> with 2 rows and 4 columns -#> a b c d -#> 1: 1 1 3 5 -#> 2: 2 2 4 6
    -# ... can be mixed with data.tables -dat = data.table(x = 3:4, y = 3:4) -cbind(dit, dat) -
    #> <dict.table> with 2 rows and 4 columns -#> a b x y -#> 1: 1 1 3 3 -#> 2: 2 2 4 4
    -dit = dict.table(a = 1:3) -add(dit, b = 3:1, d = 4:6) -
    #> <dict.table> with 3 rows and 3 columns -#> a b d -#> 1: 1 3 4 -#> 2: 2 2 5 -#> 3: 3 1 6
    -if (FALSE) { -add(dit, a = 7:9) # column 'a' already exists -} - -dit = dict.table(a = 1:3, b = 4:6) -at(dit, "a") -
    #> <dict.table> with 3 rows and 1 column -#> a -#> 1: 1 -#> 2: 2 -#> 3: 3
    at(dit, 2) -
    #> <dict.table> with 3 rows and 1 column -#> b -#> 1: 4 -#> 2: 5 -#> 3: 6
    at(dit, "a", 2) -
    #> <dict.table> with 3 rows and 2 columns -#> a b -#> 1: 1 4 -#> 2: 2 5 -#> 3: 3 6
    if (FALSE) { -at(dit, "x") # index 'x' not found -at(dit, 1:3) # index 3 exceeds length of dict.table -} - -dit = dict.table(a = 1:3, b = 4:6) -at2(dit, 1) -
    #> [1] 1 2 3
    at2(dit, "a") -
    #> [1] 1 2 3
    at2(dit, 2) -
    #> [1] 4 5 6
    if (FALSE) { -at2(dit, "x") # index 'x' not found -at2(dit, 5) # index 5 exceeds length of dict.table -} - -dit = dict.table(a = 1, b = 2) -clear(dit) -
    #> <dict.table> with 0 rows and 0 columns -#> Null data.table (0 rows and 0 cols)
    dit -
    #> <dict.table> with 1 row and 2 columns -#> a b -#> 1: 1 2
    ref_clear(dit) -dit -
    #> <dict.table> with 0 rows and 0 columns -#> Null data.table (0 rows and 0 cols)
    -d = dict.table(a = 1:2, b = 3:4) -d2 = clone(d) -ref_clear(d) -print(d2) -
    #> <dict.table> with 2 rows and 2 columns -#> a b -#> 1: 1 3 -#> 2: 2 4
    -(dit = as.dict.table(head(sleep))) -
    #> <dict.table> with 6 rows and 3 columns -#> extra group ID -#> 1: 0.7 1 1 -#> 2: -1.6 1 2 -#> 3: -0.2 1 3 -#> 4: -1.2 1 4 -#> 5: -0.1 1 5 -#> 6: 3.4 1 6
    delete_at(dit, "ID") -
    #> <dict.table> with 6 rows and 2 columns -#> extra group -#> 1: 0.7 1 -#> 2: -1.6 1 -#> 3: -0.2 1 -#> 4: -1.2 1 -#> 5: -0.1 1 -#> 6: 3.4 1
    delete_at(dit, "ID", 1) -
    #> <dict.table> with 6 rows and 1 column -#> group -#> 1: 1 -#> 2: 1 -#> 3: 1 -#> 4: 1 -#> 5: 1 -#> 6: 1
    -if (FALSE) { -delete_at(dit, "foo") # Column 'foo' not in dict.table -} - -dit = as.dict.table(head(sleep)) -discard_at(dit, "ID") -
    #> <dict.table> with 6 rows and 2 columns -#> extra group -#> 1: 0.7 1 -#> 2: -1.6 1 -#> 3: -0.2 1 -#> 4: -1.2 1 -#> 5: -0.1 1 -#> 6: 3.4 1
    discard_at(dit, "ID", 1) -
    #> <dict.table> with 6 rows and 1 column -#> group -#> 1: 1 -#> 2: 1 -#> 3: 1 -#> 4: 1 -#> 5: 1 -#> 6: 1
    discard_at(dit, "foo") # ignored -
    #> <dict.table> with 6 rows and 3 columns -#> extra group ID -#> 1: 0.7 1 1 -#> 2: -1.6 1 2 -#> 3: -0.2 1 3 -#> 4: -1.2 1 4 -#> 5: -0.1 1 5 -#> 6: 3.4 1 6
    -dit = dict.table(a = 1:3, b = as.list(4:6)) -has(dit, 1:3) # TRUE -
    #> [1] TRUE
    has(dit, 4:6) # FALSE -
    #> [1] FALSE
    has(dit, as.list(4:6)) # TRUE -
    #> [1] TRUE
    -dit = dict.table(a = 1, b = 2) -has_name(dit, "a") # TRUE -
    #> [1] TRUE
    has_name(dit, "x") # FALSE -
    #> [1] FALSE
    -d = dict.table(a = 1:4, b = 4:1) -is_empty(d) -
    #> [1] FALSE
    #> [1] TRUE
    -dit = dict.table(a = 1:3, b = 4:6) -peek_at(dit, "a") -
    #> <dict.table> with 3 rows and 1 column -#> a -#> 1: 1 -#> 2: 2 -#> 3: 3
    peek_at(dit, 1) -
    #> <dict.table> with 3 rows and 1 column -#> a -#> 1: 1 -#> 2: 2 -#> 3: 3
    peek_at(dit, 3) -
    #> <dict.table> with 0 rows and 0 columns -#> Null data.table (0 rows and 0 cols)
    peek_at(dit, "x") -
    #> <dict.table> with 0 rows and 0 columns -#> Null data.table (0 rows and 0 cols)
    peek_at(dit, "x", .default = 0) -
    #> <dict.table> with 3 rows and 1 column -#> x -#> 1: 0 -#> 2: 0 -#> 3: 0
    peek_at(dit, "a", "x", .default = 0) -
    #> <dict.table> with 3 rows and 2 columns -#> a x -#> 1: 1 0 -#> 2: 2 0 -#> 3: 3 0
    -dit = dict.table(a = 1:3, b = 4:6) -peek_at2(dit, "a") -
    #> [1] 1 2 3
    peek_at2(dit, 1) -
    #> [1] 1 2 3
    peek_at2(dit, 3) -
    #> NULL
    peek_at2(dit, 3, default = 9) -
    #> [1] 9 9 9
    peek_at2(dit, "x") -
    #> NULL
    peek_at2(dit, "x", default = 0) -
    #> [1] 0 0 0
    -dit = dict.table(a = 1:3, b = 4:6) -ref_pop(dit, "a") -
    #> [1] 1 2 3
    ref_pop(dit, 1) -
    #> [1] 4 5 6
    -if (FALSE) { -ref_pop(dit, "x") # index 'x' not found -} +
+
+

See also

+ +
-dit = dict.table(a = 1, b = 2, c = 3) -rename(dit, c("a", "b"), c("a1", "y")) -
#> <dict.table> with 1 row and 3 columns -#> a1 y c -#> 1: 1 2 3
print(dit) -
#> <dict.table> with 1 row and 3 columns -#> a b c -#> 1: 1 2 3
ref_rename(dit, c("a", "b"), c("a1", "y")) -print(dit) -
#> <dict.table> with 1 row and 3 columns -#> a1 y c -#> 1: 1 2 3
-dit = dict.table(a = 1:3) -replace_at(dit, "a", 3:1) -
#> <dict.table> with 3 rows and 1 column -#> a -#> 1: 3 -#> 2: 2 -#> 3: 1
-if (FALSE) { -replace_at(dit, "b", 4:6) # column 'b' not in dict.table -} -replace_at(dit, "b", 4:6, .add = TRUE) # ok, adds column -
#> <dict.table> with 3 rows and 2 columns -#> a b -#> 1: 1 4 -#> 2: 2 5 -#> 3: 3 6
-# Update parts of tables (second overwrites columns of the first) -dit1 = dict.table(a = 1:2, b = 3:4) -dit2 = dict.table( b = 5:6, c = 8:9) -update(dit1, dit2) -
#> <dict.table> with 2 rows and 3 columns -#> a b c -#> 1: 1 5 8 -#> 2: 2 6 9
update(dit2, dit1) -
#> <dict.table> with 2 rows and 3 columns -#> b c a -#> 1: 3 8 1 -#> 2: 4 9 2
+
+

Examples

+
# Some basic examples using some typical data.table and dict operations.
+# The constructor can take the 'key' argument known from data.table():
+require(data.table)
+#> Loading required package: data.table
+dit = dict.table(x = rep(c("b","a","c"), each = 3), y = c(1,3,6), key = "y")
+print(dit)
+#> <dict.table> with 9 rows and 2 columns
+#>    x y
+#> 1: b 1
+#> 2: a 1
+#> 3: c 1
+#> 4: b 3
+#> 5: a 3
+#> 6: c 3
+#> 7: b 6
+#> 8: a 6
+#> 9: c 6
+setkey(dit, "x")                             # sort by 'x'
+print(dit)
+#> <dict.table> with 9 rows and 2 columns
+#>    x y
+#> 1: a 1
+#> 2: a 3
+#> 3: a 6
+#> 4: b 1
+#> 5: b 3
+#> 6: b 6
+#> 7: c 1
+#> 8: c 3
+#> 9: c 6
+(add(dit, "v" = 1:9))                        # add column v = 1:9
+#> <dict.table> with 9 rows and 3 columns
+#>    x y v
+#> 1: a 1 1
+#> 2: a 3 2
+#> 3: a 6 3
+#> 4: b 1 4
+#> 5: b 3 5
+#> 6: b 6 6
+#> 7: c 1 7
+#> 8: c 3 8
+#> 9: c 6 9
+dit[y > 5]
+#> <dict.table> with 3 rows and 2 columns
+#>    x y
+#> 1: a 6
+#> 2: b 6
+#> 3: c 6
+(ref_discard_at(dit, "x"))                   # discard column 'x'
+#> <dict.table> with 9 rows and 1 column
+#>    y
+#> 1: 1
+#> 2: 3
+#> 3: 6
+#> 4: 1
+#> 5: 3
+#> 6: 6
+#> 7: 1
+#> 8: 3
+#> 9: 6
+
+try(at(dit, "x"))                            # index 'x' not found
+#> Error : index 'x' not found
+try(replace_at(dit, x = 0))                  # cannot be replaced, if it does not exist
+#> Error : column(s) not found: 'x'
+
+dit = replace_at(dit, x = 0, .add = TRUE)    # ok - re-adds column 'x' with all 0s
+peek_at(dit, "x")                            # glance at column 'x'
+#> <dict.table> with 9 rows and 1 column
+#>    x
+#> 1: 0
+#> 2: 0
+#> 3: 0
+#> 4: 0
+#> 5: 0
+#> 6: 0
+#> 7: 0
+#> 8: 0
+#> 9: 0
+has_name(dit, "x")                           # TRUE
+#> [1] TRUE
+ref_pop(dit, "x")                            # get column and remove it
+#> [1] 0 0 0 0 0 0 0 0 0
+has_name(dit, "x")                           # FALSE
+#> [1] FALSE
+
+
+# Copy and reference semantics when coercing *from* a data.table
+dat = data.table(a = 1, b = 2)
+dit = as.dict.table(dat)
+is.dict.table(dit)                           # TRUE
+#> [1] TRUE
+is.dict.table(dat)                           # FALSE
+#> [1] FALSE
+ref_replace_at(dit, "a", 9)
+dit[["a"]]                                   # 9
+#> [1] 9
+dat[["a"]]                                   # 1
+#> [1] 1
+dit.dat = as.dict.table(dat, copy = FALSE)   # init by reference
+ref_replace_at(dit.dat, "a", 9)
+dat[["a"]]                                   # 9
+#> [1] 9
+is.dict.table(dit.dat)                       # TRUE
+#> [1] TRUE
+is.dict.table(dat)                           # TRUE now as well!
+#> [1] TRUE
+
+# Coerce from dict
+d = dict(a = 1, b = 1:3)
+as.dict.table(d)
+#> <dict.table> with 3 rows and 2 columns
+#>    a b
+#> 1: 1 1
+#> 2: 1 2
+#> 3: 1 3
+
+dit = dict.table(a = 1:2, b = 1:2)
+rbind(dit, dit)
+#> <dict.table> with 4 rows and 2 columns
+#>    a b
+#> 1: 1 1
+#> 2: 2 2
+#> 3: 1 1
+#> 4: 2 2
+
+# rbind ...
+dit = dict.table(a = 1:2, b = 1:2)
+rbind(dit, dit)
+#> <dict.table> with 4 rows and 2 columns
+#>    a b
+#> 1: 1 1
+#> 2: 2 2
+#> 3: 1 1
+#> 4: 2 2
+
+# ... can be mixed with data.tables
+dat = data.table(a = 3:4, b = 3:4)
+rbind(dit, dat)  # yields a dict.table
+#> <dict.table> with 4 rows and 2 columns
+#>    a b
+#> 1: 1 1
+#> 2: 2 2
+#> 3: 3 3
+#> 4: 4 4
+rbind(dat, dit)  # yields a data.table
+#>    a b
+#> 1: 3 3
+#> 2: 4 4
+#> 3: 1 1
+#> 4: 2 2
+
+# cbind ...
+dit = dict.table(a = 1:2, b = 1:2)
+dit2 = dict.table(c = 3:4, d = 5:6)
+cbind(dit, dit2)
+#> <dict.table> with 2 rows and 4 columns
+#>    a b c d
+#> 1: 1 1 3 5
+#> 2: 2 2 4 6
+
+# ... can be mixed with data.tables
+dat = data.table(x = 3:4, y = 3:4)
+cbind(dit, dat)
+#> <dict.table> with 2 rows and 4 columns
+#>    a b x y
+#> 1: 1 1 3 3
+#> 2: 2 2 4 4
+
+dit = dict.table(a = 1:3)
+add(dit, b = 3:1, d = 4:6)
+#> <dict.table> with 3 rows and 3 columns
+#>    a b d
+#> 1: 1 3 4
+#> 2: 2 2 5
+#> 3: 3 1 6
+
+try(add(dit, a = 7:9))  # column 'a' already exists
+#> Error : name 'a' exists already
+
+dit = dict.table(a = 1:3, b = 4:6)
+at(dit, "a")
+#> <dict.table> with 3 rows and 1 column
+#>    a
+#> 1: 1
+#> 2: 2
+#> 3: 3
+at(dit, 2)
+#> <dict.table> with 3 rows and 1 column
+#>    b
+#> 1: 4
+#> 2: 5
+#> 3: 6
+at(dit, "a", 2)
+#> <dict.table> with 3 rows and 2 columns
+#>    a b
+#> 1: 1 4
+#> 2: 2 5
+#> 3: 3 6
+try(at(dit, "x"))     # index 'x' not found
+#> Error : index 'x' not found
+try(at(dit, 1:3))     # index 3 exceeds length of dict.table
+#> Error : index 3 exceeds length of dict.table, which is 2
+
+dit = dict.table(a = 1:3, b = 4:6)
+at2(dit, 1)
+#> [1] 1 2 3
+at2(dit, "a")
+#> [1] 1 2 3
+at2(dit, 2)
+#> [1] 4 5 6
+try(at2(dit, "x"))     # index 'x' not found
+#> Error : index 'x' not found
+try(at2(dit, 5))       # index 5 exceeds length of dict.table
+#> Error : index 5 exceeds length of dict.table, which is 2
+
+dit = dict.table(a = 1, b = 2)
+clear(dit)
+#> <dict.table> with 0 rows and 0 columns
+#> Null data.table (0 rows and 0 cols)
+dit
+#> <dict.table> with 1 row and 2 columns
+#>    a b
+#> 1: 1 2
+ref_clear(dit)
+dit
+#> <dict.table> with 0 rows and 0 columns
+#> Null data.table (0 rows and 0 cols)
+
+d = dict.table(a = 1:2, b = 3:4)
+d2 = clone(d)
+ref_clear(d)
+print(d2)
+#> <dict.table> with 2 rows and 2 columns
+#>    a b
+#> 1: 1 3
+#> 2: 2 4
+
+(dit = as.dict.table(head(sleep)))
+#> <dict.table> with 6 rows and 3 columns
+#>    extra group ID
+#> 1:   0.7     1  1
+#> 2:  -1.6     1  2
+#> 3:  -0.2     1  3
+#> 4:  -1.2     1  4
+#> 5:  -0.1     1  5
+#> 6:   3.4     1  6
+delete_at(dit, "ID")
+#> <dict.table> with 6 rows and 2 columns
+#>    extra group
+#> 1:   0.7     1
+#> 2:  -1.6     1
+#> 3:  -0.2     1
+#> 4:  -1.2     1
+#> 5:  -0.1     1
+#> 6:   3.4     1
+delete_at(dit, "ID", 1)
+#> <dict.table> with 6 rows and 1 column
+#>    group
+#> 1:     1
+#> 2:     1
+#> 3:     1
+#> 4:     1
+#> 5:     1
+#> 6:     1
+
+try({
+delete_at(dit, "foo")   # Column 'foo' not in dict.table
+})
+#> Error : column(s) not found: 'foo'
+
+dit = as.dict.table(head(sleep))
+discard_at(dit, "ID")
+#> <dict.table> with 6 rows and 2 columns
+#>    extra group
+#> 1:   0.7     1
+#> 2:  -1.6     1
+#> 3:  -0.2     1
+#> 4:  -1.2     1
+#> 5:  -0.1     1
+#> 6:   3.4     1
+discard_at(dit, "ID", 1)
+#> <dict.table> with 6 rows and 1 column
+#>    group
+#> 1:     1
+#> 2:     1
+#> 3:     1
+#> 4:     1
+#> 5:     1
+#> 6:     1
+discard_at(dit, "foo")  # ignored
+#> <dict.table> with 6 rows and 3 columns
+#>    extra group ID
+#> 1:   0.7     1  1
+#> 2:  -1.6     1  2
+#> 3:  -0.2     1  3
+#> 4:  -1.2     1  4
+#> 5:  -0.1     1  5
+#> 6:   3.4     1  6
+
+dit = dict.table(a = 1:3, b = as.list(4:6))
+has(dit, 1:3)            # TRUE
+#> [1] TRUE
+has(dit, 4:6)            # FALSE
+#> [1] FALSE
+has(dit, as.list(4:6))   # TRUE
+#> [1] TRUE
+
+dit = dict.table(a = 1, b = 2)
+has_name(dit, "a")    # TRUE
+#> [1] TRUE
+has_name(dit, "x")    # FALSE
+#> [1] FALSE
+
+d = dict.table(a = 1:4, b = 4:1)
+is_empty(d)
+#> [1] FALSE
+is_empty(clear(d))
+#> [1] TRUE
+
+dit = dict.table(a = 1:3, b = 4:6)
+peek_at(dit, "a")
+#> <dict.table> with 3 rows and 1 column
+#>    a
+#> 1: 1
+#> 2: 2
+#> 3: 3
+peek_at(dit, 1)
+#> <dict.table> with 3 rows and 1 column
+#>    a
+#> 1: 1
+#> 2: 2
+#> 3: 3
+peek_at(dit, 3)
+#> <dict.table> with 0 rows and 0 columns
+#> Null data.table (0 rows and 0 cols)
+peek_at(dit, "x")
+#> <dict.table> with 0 rows and 0 columns
+#> Null data.table (0 rows and 0 cols)
+peek_at(dit, "x", .default = 0)
+#> <dict.table> with 3 rows and 1 column
+#>    x
+#> 1: 0
+#> 2: 0
+#> 3: 0
+peek_at(dit, "a", "x", .default = 0)
+#> <dict.table> with 3 rows and 2 columns
+#>    a x
+#> 1: 1 0
+#> 2: 2 0
+#> 3: 3 0
+
+dit = dict.table(a = 1:3, b = 4:6)
+peek_at2(dit, "a")
+#> [1] 1 2 3
+peek_at2(dit, 1)
+#> [1] 1 2 3
+peek_at2(dit, 3)
+#> NULL
+peek_at2(dit, 3, default = 9)
+#> [1] 9 9 9
+peek_at2(dit, "x")
+#> NULL
+peek_at2(dit, "x", default = 0)
+#> [1] 0 0 0
+
+dit = dict.table(a = 1:3, b = 4:6)
+ref_pop(dit, "a")
+#> [1] 1 2 3
+ref_pop(dit, 1)
+#> [1] 4 5 6
+
+try({
+ref_pop(dit, "x")  # index 'x' not found
+})
+#> Error : index 'x' not found
+
+dit = dict.table(a = 1, b = 2, c = 3)
+rename(dit, c("a", "b"), c("a1", "y"))
+#> <dict.table> with 1 row and 3 columns
+#>    a1 y c
+#> 1:  1 2 3
+print(dit)
+#> <dict.table> with 1 row and 3 columns
+#>    a b c
+#> 1: 1 2 3
+ref_rename(dit, c("a", "b"), c("a1", "y"))
+print(dit)
+#> <dict.table> with 1 row and 3 columns
+#>    a1 y c
+#> 1:  1 2 3
+
+dit = dict.table(a = 1:3)
+replace_at(dit, "a", 3:1)
+#> <dict.table> with 3 rows and 1 column
+#>    a
+#> 1: 3
+#> 2: 2
+#> 3: 1
+
+try({
+replace_at(dit, "b", 4:6)               # column 'b' not in dict.table
+})
+#> Error : column(s) not found: 'b'
+replace_at(dit, "b", 4:6, .add = TRUE)  # ok, adds column
+#> <dict.table> with 3 rows and 2 columns
+#>    a b
+#> 1: 1 4
+#> 2: 2 5
+#> 3: 3 6
+
+# Update parts of tables (second overwrites columns of the first)
+dit1 = dict.table(a = 1:2, b = 3:4)
+dit2 = dict.table(         b = 5:6, c = 8:9)
+update(dit1, dit2)
+#> <dict.table> with 2 rows and 3 columns
+#>    a b c
+#> 1: 1 5 8
+#> 2: 2 6 9
+update(dit2, dit1)
+#> <dict.table> with 2 rows and 3 columns
+#>    b c a
+#> 1: 3 8 1
+#> 2: 4 9 2
+
+
+
- - - + + diff --git a/docs/reference/dictS3.html b/docs/reference/dictS3.html index df024763..82afc0f4 100644 --- a/docs/reference/dictS3.html +++ b/docs/reference/dictS3.html @@ -1,81 +1,18 @@ - - - - - - - -A Dictionary — DictS3 • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -A Dictionary — DictS3 • container - - - - - - - - - - + + - - - - -
-
- -
- -
+
-

The Dict initially was developed to resemble Python's +

The Dict initially was developed to resemble Python's dict type, but by now offers both more features and flexibility, for example, by providing both associative key-value pair as well as positional array semantics. -It is implemented as a specialized associative Container thus sharing -all Container methods with some of them being adapted to account for +It is implemented as a specialized associative Container thus sharing +all Container methods with some of them being adapted to account for the key-value pair semantic. All elements must be named.

-
dict(...)
-
-as.dict(x)
+    
+
dict(...)
+
+as.dict(x)
+
+is.dict(x)
+
-is.dict(x)
+
+

Arguments

+
...
+

elements put into the Dict.

-

Arguments

- - - - - - - - - - -
...

elements put into the Dict.

x

R object of ANY type for as.dict() and is.dict() -or of class Dict for the S3 methods.

-

Details

+
x
+

R object of ANY type for as.dict() and is.dict() +or of class Dict for the S3 methods.

+
+
+

Details

Internally, all key-value pairs are stored in a hash-table and the elements are sorted lexicographically by their keys. Methods that alter Dict objects usually come in two versions providing either copy or reference semantics where the latter start with -'ref_' to note the reference semantic, for example, add() and ref_add().

-
    -
  • dict(...) initializes and returns an object of class Dict

  • -
- -
    -
  • as.dict(x) coerces x to a dictionary

  • -
- -
    -
  • is.dict(x) returns TRUE if x is of class Dict +'ref_' to note the reference semantic, for example, add() and ref_add().

    +
    • dict(...) initializes and returns an object of class Dict

    • +
    • as.dict(x) coerces x to a dictionary

    • +
    • is.dict(x) returns TRUE if x is of class Dict and FALSE otherwise.

    • -
    - -
      -
    • x + y combines x and y into a new dict by updating x +

    • x + y combines x and y into a new dict by updating x by y (see also [update()]).

    • -
    - -
      -
    • x - y removes all keys from x that appear in y.

    • -
    - -
      -
    • x & y returns a copy of x keeping only the keys that +

    • x - y removes all keys from x that appear in y.

    • +
    • x & y returns a copy of x keeping only the keys that are common in both (key intersection), that is, all keys in x that do not exist in y are removed.

    • -
    - -
      -
    • x | y returns a copy of x extended by all elements of +

    • x | y returns a copy of x extended by all elements of y that are stored at keys (or names) that do not exist in x, thereby combining the keys of both objects (set union of keys).

    • -
    - -
    • add(.x, ...) and ref_add(.x, ...) adds key = value pairs to .x. If any of the keys already exists, an error is given.

    • -
    - -
    • replace(.x, old, new) and ref_replace(.x, old) try to find element old and replace it with element new. If old does not exist, an error is raised.

    • -
    - -
    • update(object, other) and ref_update(object, other) adds elements of other dict for keys not yet in object and replaces the values of existing keys.

    • -
    - -

    See also

    - -

    See container() for all inherited methods. For the full class -documentation see Dict and it's superclass Container.

    - -

    Examples

    -
    d = dict(b = "one", a = 1, f = mean, na = NA) -print(d) -
    #> {a = 1, b = "one", f = <<function>>, na = NA}
    names(d) -
    #> [1] "a" "b" "f" "na"
    -if (FALSE) { -dict(a = 1, 2) # all elements must be named -} - -# Coercion -as.dict(list(A = 1:3, B = "b")) -
    #> {A = (1L 2L 3L), B = "b"}
    as.dict(c(x = 1, y = "x", z = 2 + 3)) -
    #> {x = "1", y = "x", z = "5"}
    # Math -d = dict(a = rnorm(1), b = rnorm(1)) -abs(d) -
    #> {a = 1.400044, b = 0.2553171}
    cumsum(d) -
    #> {a = -1.400044, b = -1.144726}
    round(d) -
    #> {a = -1, b = 0}
    exp(d) -
    #> {a = 0.2465862, b = 1.290871}
    -# Summary -range(d) -
    #> [1] -1.4000435 0.2553171
    min(d) -
    #> [1] -1.400044
    max(d) -
    #> [1] 0.2553171
    -d1 = dict(a = 1, b = list(1, 2)) -d2 = dict(a = 2, b = list(1, 2)) -d1 + d2 # same as update(d, d2) -
    #> {a = 2, b = list(1, 2)}
    d2 + d1 # same as update(d2, d) -
    #> {a = 1, b = list(1, 2)}
    if (FALSE) { -c(d1, d2) # duplicated keys are not allowed for Dict -} -d1 - d2 -
    #> {}
    d2 - d1 -
    #> {}
    d1 - d1 -
    #> {}
    -d1 = dict(a = 1, b = 2) -d2 = dict(a = 10, x = 4) -d1 & d2 # {a = 1} -
    #> {a = 1}
    -d1 | d2 # {a = 1, b = 2, x = 4} -
    #> {a = 1, b = 2, x = 4}
    - -d = dict(a = 1) -add(d, b = 2, co = container(1:3)) -
    #> {a = 1, b = 2, co = [(1L 2L 3L)]}
    -if (FALSE) { -add(d, a = 7:9) # key 'a' already in Dict -} - -d = dict(a = 1, b = "z") -replace(d, 1, 1:5) -
    #> {a = (1L 2L 3L 4L ...), b = "z"}
    replace(d, "z", "a") -
    #> {a = 1, b = "a"}
    -if (FALSE) { -replace(d, "a", 2) # old element ("a") is not in Dict -} +
+
+

See also

+

See container() for all inherited methods. For the full class +documentation see Dict and it's superclass Container.

+
-d1 = dict(a = 1, b = 2) -d2 = dict( b = 0, c = 3) -update(d1, d2) # {a = 1, b = 0, c = 3} -
#> {a = 1, b = 0, c = 3}
update(d2, d1) # {a = 1, b = 2, c = 3} -
#> {a = 1, b = 2, c = 3}
+
+

Examples

+
d = dict(b = "one", a = 1, f = mean, na = NA)
+print(d)
+#> {a = 1, b = "one", f = <<function>>, na = NA}
+names(d)
+#> [1] "a"  "b"  "f"  "na"
+
+try(dict(a = 1, 2))   # all elements must be named
+#> Error : all elements must be named
+
+# Coercion
+as.dict(list(A = 1:3, B = "b"))
+#> {A = (1L 2L 3L), B = "b"}
+as.dict(c(x = 1, y = "x", z = 2 + 3))
+#> {x = "1", y = "x", z = "5"}
+# Math
+d = dict(a = rnorm(1), b = rnorm(1))
+abs(d)
+#> {a = 1.590916, b = 1.295328}
+cumsum(d)
+#> {a = -1.590916, b = -0.2955879}
+round(d)
+#> {a = -2, b = 1}
+exp(d)
+#> {a = 0.203739, b = 3.652193}
+
+# Summary
+range(d)
+#> [1] -1.590916  1.295328
+min(d)
+#> [1] -1.590916
+max(d)
+#> [1] 1.295328
+
+d1 = dict(a = 1, b = list(1, 2))
+d2 = dict(a = 2, b = list(1, 2))
+d1 + d2      # same as update(d, d2)
+#> {a = 2, b = list(1, 2)}
+d2 + d1      # same as update(d2, d)
+#> {a = 1, b = list(1, 2)}
+try({
+c(d1, d2)    # duplicated keys are not allowed for Dict
+})
+#> Error : duplicated keys are not allowed
+d1 - d2
+#> {}
+d2 - d1
+#> {}
+d1 - d1
+#> {}
+
+d1 = dict(a = 1, b = 2)
+d2 = dict(a = 10, x = 4)
+d1 & d2      # {a = 1}
+#> {a = 1}
+
+d1 | d2      # {a = 1, b = 2, x = 4}
+#> {a = 1, b = 2, x = 4}
+
+
+d = dict(a = 1)
+add(d, b = 2, co = container(1:3))
+#> {a = 1, b = 2, co = [(1L 2L 3L)]}
+
+try(add(d, a = 7:9))  # key 'a' already in Dict
+#> Error : name 'a' exists already
+
+d = dict(a = 1, b = "z")
+replace(d, 1, 1:5)
+#> {a = (1L 2L 3L 4L ...), b = "z"}
+replace(d, "z", "a")
+#> {a = 1, b = "a"}
+
+try({
+replace(d, "a", 2)              # old element ("a") is not in Dict
+})
+#> Error : old element ("a") is not in Dict
+
+d1 = dict(a = 1, b = 2)
+d2 = dict(       b = 0, c = 3)
+update(d1, d2)  # {a = 1, b = 0, c = 3}
+#> {a = 1, b = 0, c = 3}
+update(d2, d1)  # {a = 1, b = 2, c = 3}
+#> {a = 1, b = 2, c = 3}
+
+
+
- - - + + diff --git a/docs/reference/discard.html b/docs/reference/discard.html index 99d4e7f3..c8607f40 100644 --- a/docs/reference/discard.html +++ b/docs/reference/discard.html @@ -1,76 +1,13 @@ - - - - - - - -Discard Container Elements — discard • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Discard Container Elements — discard • container - - - - + + -
-
- -
- -
+
@@ -203,67 +129,71 @@

Discard Container Elements

ignore the attempt.

-
discard(.x, ...)
-
-ref_discard(.x, ...)
+    
+
discard(.x, ...)
+
+ref_discard(.x, ...)
+
+# S3 method for Container
+discard(.x, ...)
+
+# S3 method for Container
+ref_discard(.x, ...)
+
-# S3 method for Container -discard(.x, ...) +
+

Arguments

+
.x
+

any R object.

-# S3 method for Container -ref_discard(.x, ...)
-

Arguments

- - - - - - - - - - -
.x

any R object.

...

elements to be discarded.

+
...
+

elements to be discarded.

-

Value

+
+
+

Value

+ -

For Container, an object of class Container (or one of the +

For Container, an object of class Container (or one of the respective derived classes).

+
-

Examples

-
-s = setnew("a", num = 1:3, data = iris) -print(s) -
#> {"a", num = (1L 2L 3L), data = <<data.frame(150x5)>>}
discard(s, 1:3, "a") -
#> {data = <<data.frame(150x5)>>}
discard(s, iris) -
#> {"a", num = (1L 2L 3L)}
discard(s, "b") # ignored -
#> {"a", num = (1L 2L 3L), data = <<data.frame(150x5)>>}
+
+

Examples

+

+s = setnew("a", num = 1:3, data = iris)
+print(s)
+#> {"a", num = (1L 2L 3L), data = <<data.frame(150x5)>>}
+discard(s, 1:3, "a")
+#> {data = <<data.frame(150x5)>>}
+discard(s, iris)
+#> {"a", num = (1L 2L 3L)}
+discard(s, "b")  # ignored
+#> {"a", num = (1L 2L 3L), data = <<data.frame(150x5)>>}
+
+
+
- - - + + diff --git a/docs/reference/discard_at.html b/docs/reference/discard_at.html index 46f9a5d4..db1c4e72 100644 --- a/docs/reference/discard_at.html +++ b/docs/reference/discard_at.html @@ -1,76 +1,13 @@ - - - - - - - -Discard Elements at Indices — discard_at • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Discard Elements at Indices — discard_at • container - - + + - - -
-
- -
- -
+
@@ -203,100 +129,109 @@

Discard Elements at Indices

or both. Invalid indices are ignored.

-
discard_at(.x, ...)
-
-ref_discard_at(.x, ...)
+    
+
discard_at(.x, ...)
+
+ref_discard_at(.x, ...)
+
+# S3 method for Container
+discard_at(.x, ...)
+
+# S3 method for Container
+ref_discard_at(.x, ...)
+
+# S3 method for dict.table
+discard_at(.x, ...)
+
+# S3 method for dict.table
+ref_discard_at(.x, ...)
+
-# S3 method for Container -discard_at(.x, ...) +
+

Arguments

+
.x
+

any R object.

-# S3 method for Container -ref_discard_at(.x, ...) -# S3 method for dict.table -discard_at(.x, ...) +
...
+

indices at which values are to be discarded.

-# S3 method for dict.table -ref_discard_at(.x, ...)
+
+
+

Value

+ -

Arguments

- - - - - - - - - - -
.x

any R object.

...

indices at which values are to be discarded.

+

For Container, an object of class Container (or one of the +respective derived classes).

-

Value

-

For Container, an object of class Container (or one of the -respective derived classes).

For dict.table, an object of class dict.table.

+
-

Examples

-
-co = container(a = 1, b = 2, 3) -discard_at(co, "a", "b") # [3] -
#> [3]
discard_at(co, 1:2) # [3] -
#> [3]
discard_at(co, "a", 3) # [b = 2] -
#> [b = 2]
discard_at(co, "x") # ignored -
#> [a = 1, b = 2, 3]
-dit = as.dict.table(head(sleep)) -discard_at(dit, "ID") -
#> <dict.table> with 6 rows and 2 columns -#> extra group -#> 1: 0.7 1 -#> 2: -1.6 1 -#> 3: -0.2 1 -#> 4: -1.2 1 -#> 5: -0.1 1 -#> 6: 3.4 1
discard_at(dit, "ID", 1) -
#> <dict.table> with 6 rows and 1 column -#> group -#> 1: 1 -#> 2: 1 -#> 3: 1 -#> 4: 1 -#> 5: 1 -#> 6: 1
discard_at(dit, "foo") # ignored -
#> <dict.table> with 6 rows and 3 columns -#> extra group ID -#> 1: 0.7 1 1 -#> 2: -1.6 1 2 -#> 3: -0.2 1 3 -#> 4: -1.2 1 4 -#> 5: -0.1 1 5 -#> 6: 3.4 1 6
+
+

Examples

+

+co = container(a = 1, b = 2, 3)
+discard_at(co, "a", "b")         # [3]
+#> [3]
+discard_at(co, 1:2)              # [3]
+#> [3]
+discard_at(co, "a", 3)           # [b = 2]
+#> [b = 2]
+discard_at(co, "x")              # ignored
+#> [a = 1, b = 2, 3]
+
+dit = as.dict.table(head(sleep))
+discard_at(dit, "ID")
+#> <dict.table> with 6 rows and 2 columns
+#>    extra group
+#> 1:   0.7     1
+#> 2:  -1.6     1
+#> 3:  -0.2     1
+#> 4:  -1.2     1
+#> 5:  -0.1     1
+#> 6:   3.4     1
+discard_at(dit, "ID", 1)
+#> <dict.table> with 6 rows and 1 column
+#>    group
+#> 1:     1
+#> 2:     1
+#> 3:     1
+#> 4:     1
+#> 5:     1
+#> 6:     1
+discard_at(dit, "foo")  # ignored
+#> <dict.table> with 6 rows and 3 columns
+#>    extra group ID
+#> 1:   0.7     1  1
+#> 2:  -1.6     1  2
+#> 3:  -0.2     1  3
+#> 4:  -1.2     1  4
+#> 5:  -0.1     1  5
+#> 6:   3.4     1  6
+
+
+
- - - + + diff --git a/docs/reference/has.html b/docs/reference/has.html index 89497072..75bab824 100644 --- a/docs/reference/has.html +++ b/docs/reference/has.html @@ -1,75 +1,12 @@ - - - - - - - -Check for Element — has • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Check for Element — has • container - - + + - - -
-
- -
- -
+
@@ -201,81 +127,90 @@

Check for Element

Check for Element

-
has(x, ...)
+    
+
has(x, ...)
+
+# S3 method for Container
+has(x, elem, ...)
+
+# S3 method for dict.table
+has(x, column, ...)
+
-# S3 method for Container -has(x, elem, ...) +
+

Arguments

+
x
+

any R object.

-# S3 method for dict.table -has(x, column, ...)
-

Arguments

- - - - - - - - - - - - - - - - - - -
x

any R object.

...

additional arguments to be passed to or from methods.

elem

some element to be found.

column

vector of values with the same length as the number of rows -of the dict.table.

+
...
+

additional arguments to be passed to or from methods.

-

Value

-

TRUE if element is in x and otherwise FALSE.

-

For dict.table, TRUE if column exists in x otherwise FALSE.

-

See also

+
elem
+

some element to be found.

+ - +
column
+

vector of values with the same length as the number of rows +of the dict.table.

-

Examples

-
-co = container(1, 2, mean) -has(co, 1) # TRUE -
#> [1] TRUE
has(co, mean) # TRUE -
#> [1] TRUE
has(co, 1:2) # FALSE -
#> [1] FALSE
-dit = dict.table(a = 1:3, b = as.list(4:6)) -has(dit, 1:3) # TRUE -
#> [1] TRUE
has(dit, 4:6) # FALSE -
#> [1] FALSE
has(dit, as.list(4:6)) # TRUE -
#> [1] TRUE
+
+
+

Value

+ + +

TRUE if element is in x and otherwise FALSE.

+ + +

For dict.table, TRUE if column exists in x otherwise FALSE.

+
+
+

See also

+ +
+ +
+

Examples

+

+co = container(1, 2, mean)
+has(co, 1)                   # TRUE
+#> [1] TRUE
+has(co, mean)                # TRUE
+#> [1] TRUE
+has(co, 1:2)                 # FALSE
+#> [1] FALSE
+
+dit = dict.table(a = 1:3, b = as.list(4:6))
+has(dit, 1:3)            # TRUE
+#> [1] TRUE
+has(dit, 4:6)            # FALSE
+#> [1] FALSE
+has(dit, as.list(4:6))   # TRUE
+#> [1] TRUE
+
+
+
- - - + + diff --git a/docs/reference/has_name.html b/docs/reference/has_name.html index 44820300..ab4f4337 100644 --- a/docs/reference/has_name.html +++ b/docs/reference/has_name.html @@ -1,75 +1,12 @@ - - - - - - - -Check for Name — has_name • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Check for Name — has_name • container + + - - - - -
-
- -
- -
+
@@ -201,72 +127,82 @@

Check for Name

Check for Name

-
has_name(x, name)
+    
+
has_name(x, name)
+
+# S3 method for Container
+has_name(x, name)
+
+# S3 method for dict.table
+has_name(x, name)
+
-# S3 method for Container -has_name(x, name) +
+

Arguments

+
x
+

any R object.

-# S3 method for dict.table -has_name(x, name)
-

Arguments

- - - - - - - - - - -
x

any R object.

name

character the name to be found.

+
name
+

character the name to be found.

-

Value

+
+
+

Value

+ -

TRUE if name is in x and otherwise FALSE.

-

For dict.table TRUE if the dict.table objects has the given -column name, otherwise FALSE.

-

See also

+

TRUE if name is in x and otherwise FALSE.

- -

Examples

-
-co = container(a = 1, 2, f = mean) -has_name(co, "a") # TRUE -
#> [1] TRUE
has_name(co, "f") # TRUE -
#> [1] TRUE
has_name(co, "2") # FALSE -
#> [1] FALSE
-dit = dict.table(a = 1:2, b = 3:4) -has_name(dit, "a") # TRUE -
#> [1] TRUE
has_name(dit, "x") # FALSE -
#> [1] FALSE
+

For dict.table

+

+

TRUE if the dict.table objects has the given +column name, otherwise FALSE.

+
+
+

See also

+ +
+ +
+

Examples

+

+co = container(a = 1, 2, f = mean)
+has_name(co, "a")    # TRUE
+#> [1] TRUE
+has_name(co, "f")    # TRUE
+#> [1] TRUE
+has_name(co, "2")    # FALSE
+#> [1] FALSE
+
+dit = dict.table(a = 1:2, b = 3:4)
+has_name(dit, "a")   # TRUE
+#> [1] TRUE
+has_name(dit, "x")   # FALSE
+#> [1] FALSE
+
+
+
- - - + + diff --git a/docs/reference/index.html b/docs/reference/index.html index c3831352..791805ef 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -1,74 +1,12 @@ - - - - - - - -Function reference • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Function reference • container - - + + - - -
-
- -
- -
+
- - - - - - - - - - -
-

Container

-

A container can be considered a base R list with extended functionality.

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+

Container

+

A container can be considered a base R list with extended functionality.

+

Container

Container Class

+

container() cont() as.container() as.cont() is.container() as.list(<Container>) length(<Container>) names(<Container>) `names<-`(<Container>)

Container - Enhancing R's list

+

clear() ref_clear()

Clear a Container

+

clone()

Clone an Object

+

container_options() getContainerOption()

Set Container Package Options

+

unpack()

Unpack Nested Objects

-

add or replace

+
+

add or replace

+

add() ref_add()

Add Elements to Containers

+

replace() ref_replace()

Replace Values in Containers Safely

+

replace_at() ref_replace_at()

Replace Values at Indices Safely

+

`[<-`(<Container>) `[[<-`(<Container>) `$<-`(<Container>)

Replace Parts of a Container

-

extract

+
+

extract

+

at()

Extract Elements Safely

+

at2()

Extract Single Elements Safely

+

peek_at()

Peek at Indices

+

peek_at2()

Peek at Single Index

+

`[`(<Container>) `[[`(<Container>)

Extract Parts of a Container Object

-

inspect

+
+

inspect

+

count()

Count Elements

+

has()

Check for Element

+

has_name()

Check for Name

+

is_empty()

Check if Object is Empty

-

remove

+
+

remove

+

delete() ref_delete()

Delete Container Elements Safely

+

delete_at() ref_delete_at()

Delete Elements at Indices Safely

+

discard() ref_discard()

Discard Container Elements

+

discard_at() ref_discard_at()

Discard Elements at Indices

+

ref_pop() ref_popleft()

Get and Remove Element

-

update

+
+

update

+

rename() ref_rename()

Rename Elements Safely

+

ref_update() update(<Container>) update(<dict.table>) update(<list>)

Update Object with Elements from Another Object

-

Deque

-

Derives all Container methods. Can also be used to mimic stacks or simple queues.

+
+

Deque

+

Derives all Container methods. Can also be used to mimic stacks or simple queues.

+

Deque

Deque Class

-

deque() as.deque() is.deque()

+
+

deque() as.deque() is.deque()

Deque - Double-Ended Queue

+

addleft() ref_addleft()

Add Elements to the Left of Deques

+

peekleft() peek()

Peek at Left or Right of a Deque

+

ref_rev() rev(<Deque>)

Reverse Elements

+

rotate() ref_rotate()

Rotate Elements

-

Set, OrderedSet

-

Derives all Container methods. Set elements are always unique.

+
+

Set, OrderedSet

+

Derives all Container methods. Set elements are always unique.

+

Set

Set Class

+

OrderedSet

OrderedSet Class

+

setnew() as.set() as.orderedset() is.set() is.orderedset()

Set and ordered Set

-

Dict

-

Derives all Container methods. All Dict elements must be named and are always sorted by their name.

+
+

Dict

+

Derives all Container methods. All Dict elements must be named and are always sorted by their name.

+

Dict

Dict Class

-

dict() as.dict() is.dict()

+
+

dict() as.dict() is.dict()

A Dictionary

-

dict.table

-

The dict.table is a mix of a dict and a data.table and derives all data.table and most of the dict/container methods.

+
+

dict.table

+

The dict.table is a mix of a dict and a data.table and derives all data.table and most of the dict/container methods.

+

dict.table() as.dict.table() is.dict.table() rbind(<dict.table>) cbind(<dict.table>)

Combining Dict and data.table

-

Iterator

-

Iterate over sequences.

+
+

Iterator

+

Iterate over sequences.

+

Iterable

Iterable abstract class interface

+

Iterator

Iterator Class

+

iter() is.iterator() is.iterable() begin() get_value() get_next() has_next() has_value() pos() next_iter() reset_iter() length(<Iterator>)

Iterate over Sequences

-

Operators

+
+

Operators

+

`+`(<Container>) `-`(<Container>) `+`(<Deque>) `-`(<Deque>) `+`(<Dict>) `-`(<Dict>) `+`(<Set>) `-`(<Set>)

Arithmetic Operators

+

`==`(<Container>) `!=`(<Container>) `<`(<Container>) `>`(<Container>) `<=`(<Container>) `>=`(<Container>)

Comparison Operators

+

`&`(<Dict>) `|`(<Dict>) `&`(<Set>) `|`(<Set>)

Logic Operators

-

Depecated

-

Deprecated functions.

+
+

Depecated

+

Deprecated functions.

+

empty() size() sortkey() values() keys()

Deprecated Functions

- +
+
-
- - + + diff --git a/docs/reference/is_empty.html b/docs/reference/is_empty.html index 386dcedb..abcda74f 100644 --- a/docs/reference/is_empty.html +++ b/docs/reference/is_empty.html @@ -1,75 +1,12 @@ - - - - - - - -Check if Object is Empty — is_empty • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Check if Object is Empty — is_empty • container - - + + - - -
-
- -
- -
+
@@ -201,62 +127,66 @@

Check if Object is Empty

Check if Object is Empty

-
is_empty(x)
-
-# S3 method for Container
-is_empty(x)
-
-# S3 method for dict.table
-is_empty(x)
+
+
is_empty(x)
+
+# S3 method for Container
+is_empty(x)
+
+# S3 method for dict.table
+is_empty(x)
+
-

Arguments

- - - - - - -
x

any R object.

+
+

Arguments

+
x
+

any R object.

-

Value

+
+
+

Value

+ -

TRUE if object is empty otherwise FALSE.

+

TRUE if object is empty otherwise FALSE.

+
-

Examples

-
-co = container(1, 2) -is_empty(co) -
#> [1] FALSE
is_empty(clear(co)) -
#> [1] TRUE
-d = dict.table(a = 1:4, b = 4:1) -is_empty(d) -
#> [1] FALSE
is_empty(clear(d)) -
#> [1] TRUE
+
+

Examples

+

+co = container(1, 2)
+is_empty(co)
+#> [1] FALSE
+is_empty(clear(co))
+#> [1] TRUE
+
+d = dict.table(a = 1:4, b = 4:1)
+is_empty(d)
+#> [1] FALSE
+is_empty(clear(d))
+#> [1] TRUE
+
+
+
- - - + + diff --git a/docs/reference/iterS3.html b/docs/reference/iterS3.html index 18f63ebe..cd699044 100644 --- a/docs/reference/iterS3.html +++ b/docs/reference/iterS3.html @@ -1,78 +1,15 @@ - - - - - - - -Iterate over Sequences — iterS3 • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Iterate over Sequences — iterS3 • container - - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -204,133 +130,153 @@

Iterate over Sequences

An Iterator is an object that allows to iterate over sequences. It implements next_iter() and get_value() to iterate and retrieve the value of the sequence it is associated with. -For documentation of the methods see Iterator.

+For documentation of the methods see Iterator.

-
iter(x, ...)
-
-# S3 method for Container
-iter(x, ...)
-
-# S3 method for default
-iter(x, ...)
-
-is.iterator(x)
-
-is.iterable(x)
-
-begin(it)
-
-get_value(it)
-
-get_next(it)
-
-has_next(it)
-
-has_value(it)
-
-pos(it)
-
-next_iter(it)
+    
+
iter(x, ...)
+
+# S3 method for Container
+iter(x, ...)
+
+# S3 method for default
+iter(x, ...)
+
+is.iterator(x)
+
+is.iterable(x)
+
+begin(it)
+
+get_value(it)
+
+get_next(it)
+
+has_next(it)
+
+has_value(it)
+
+pos(it)
+
+next_iter(it)
+
+reset_iter(it)
+
+# S3 method for Iterator
+length(x)
+
-reset_iter(it) +
+

Arguments

+
x
+

an object of class Iterable or any other R object. In the +latter case, x will always be coerced to a base R list prior to creating +the Iterator.

-# S3 method for Iterator -length(x)
-

Arguments

- - - - - - - - - - - - - - -
x

an object of class Iterable or any other R object. In the -latter case, x will always be coerced to a base R list prior to creating -the Iterator.

...

other parameters passed to or from methods

it

Iterator object

+
...
+

other parameters passed to or from methods

-

Value

-

length returns the number of elements that can be iterated over.

-

See also

+
it
+

Iterator object

-

For the class documentation see Iterator.

+
+
+

Value

+ -

Examples

-
# Numeric Vector -v = 1:3 -it = iter(v) -it -
#> <Iterator> at position 0 / 3
-if (FALSE) { -it$get_value() # iterator does not point at a value -} +

length returns the number of elements that can be iterated over.

+
+
+

See also

+

For the class documentation see Iterator.

+
-has_value(it) -
#> [1] FALSE
has_next(it) -
#> [1] TRUE
next_iter(it) -
#> <Iterator> at position 1 / 3
get_value(it) -
#> [1] 1
get_next(it) -
#> [1] 2
get_next(it) -
#> [1] 3
it -
#> <Iterator> at position 3 / 3
has_next(it) -
#> [1] FALSE
begin(it) -
#> <Iterator> at position 1 / 3
get_value(it) -
#> [1] 1
reset_iter(it) -
#> <Iterator> at position 0 / 3
-# Works on copy of Container -co = container(1, 2, 3) -it = iter(co) -get_next(it) -
#> [[1]] -#> [1] 1 -#>
ref_discard(co, 2) -co -
#> [1, 3]
it -
#> <Iterator> at position 1 / 3
get_next(it) -
#> [[1]] -#> [1] 2 -#>
ref_clear(co) -co -
#> []
it -
#> <Iterator> at position 2 / 3
get_next(it) -
#> [[1]] -#> [1] 3 -#>
begin(it) -
#> <Iterator> at position 1 / 3
+
+

Examples

+
# Numeric Vector
+v = 1:3
+it = iter(v)
+it
+#> <Iterator> at position 0 / 3 
+
+try(it$get_value())  # iterator does not point at a value
+#> Error in it$get_value() : iterator does not point at a value
+
+has_value(it)
+#> [1] FALSE
+has_next(it)
+#> [1] TRUE
+next_iter(it)
+#> <Iterator> at position 1 / 3 
+get_value(it)
+#> [1] 1
+get_next(it)
+#> [1] 2
+get_next(it)
+#> [1] 3
+it
+#> <Iterator> at position 3 / 3 
+has_next(it)
+#> [1] FALSE
+begin(it)
+#> <Iterator> at position 1 / 3 
+get_value(it)
+#> [1] 1
+reset_iter(it)
+#> <Iterator> at position 0 / 3 
+
+# Works on copy of Container
+co = container(1, 2, 3)
+it = iter(co)
+get_next(it)
+#> [[1]]
+#> [1] 1
+#> 
+ref_discard(co, 2)
+co
+#> [1, 3]
+it
+#> <Iterator> at position 1 / 3 
+get_next(it)
+#> [[1]]
+#> [1] 2
+#> 
+ref_clear(co)
+co
+#> []
+it
+#> <Iterator> at position 2 / 3 
+get_next(it)
+#> [[1]]
+#> [1] 3
+#> 
+begin(it)
+#> <Iterator> at position 1 / 3 
+
+
+
- - - + + diff --git a/docs/reference/peek.html b/docs/reference/peek.html index 87fb256f..246522bc 100644 --- a/docs/reference/peek.html +++ b/docs/reference/peek.html @@ -1,77 +1,14 @@ - - - - - - - -Peek at Left or Right of a Deque — peek • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Peek at Left or Right of a Deque — peek • container - - - - - - - - - - + + - - - - -
-
- -
- -
+
@@ -205,74 +131,81 @@

Peek at Left or Right of a Deque

access, that is, it remains valid even if peeked elements don't exist.

-
peekleft(x, default = NULL)
-
-peek(x, default = NULL)
-
-# S3 method for Deque
-peek(x, default = NULL)
+    
+
peekleft(x, default = NULL)
+
+peek(x, default = NULL)
+
+# S3 method for Deque
+peek(x, default = NULL)
+
+# S3 method for Deque
+peekleft(x, default = NULL)
+
-# S3 method for Deque -peekleft(x, default = NULL)
+
+

Arguments

+
x
+

a Deque object.

-

Arguments

- - - - - - - - - - -
x

a Deque object.

default

value to be returned if peeked value does not exist.

-

Value

+
default
+

value to be returned if peeked value does not exist.

-

The first (peekleft) or last (peek) element.

-

Details

+
+
+

Value

+ +

The first (peekleft) or last (peek) element.

+
+
+

Details

peek peek at last element of a Deque.

peekleft peek at first element of a Deque.

-

See also

- -

at2() for strict element extraction

+
+
+

See also

+

at2() for strict element extraction

+
-

Examples

-
# Deque -d = deque(1, 2, 3) -peek(d) -
#> [1] 3
peekleft(d) -
#> [1] 1
peek(deque()) -
#> NULL
peek(deque(), default = 0) -
#> [1] 0
peekleft(deque(), default = 0) -
#> [1] 0
+
+

Examples

+
# Deque
+d = deque(1, 2, 3)
+peek(d)
+#> [1] 3
+peekleft(d)
+#> [1] 1
+peek(deque())
+#> NULL
+peek(deque(), default = 0)
+#> [1] 0
+peekleft(deque(), default = 0)
+#> [1] 0
+
+
+
- - - + + diff --git a/docs/reference/peek_at.html b/docs/reference/peek_at.html index 76048132..b3d13815 100644 --- a/docs/reference/peek_at.html +++ b/docs/reference/peek_at.html @@ -1,77 +1,14 @@ - - - - - - - -Peek at Indices — peek_at • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Peek at Indices — peek_at • container - - - - - - - - - - - - + + - - -
-
- -
- -
+
@@ -205,112 +131,130 @@

Peek at Indices

access, that is, it remains valid even if elements don't exist.

-
peek_at(.x, ...)
+    
+
peek_at(.x, ...)
+
+# S3 method for Container
+peek_at(.x, ..., .default = NULL)
+
+# S3 method for dict.table
+peek_at(.x, ..., .default = NULL)
+
+ +
+

Arguments

+
.x
+

an R object of the respective class.

+ -# S3 method for Container -peek_at(.x, ..., .default = NULL) +
...
+

indices of elements to be extracted

-# S3 method for dict.table -peek_at(.x, ..., .default = NULL)
-

Arguments

- - - - - - - - - - - - - - -
.x

an R object of the respective class.

...

indices of elements to be extracted

.default

value to be returned if peeked value does not exist.

+
.default
+

value to be returned if peeked value does not exist.

-

Value

+
+
+

Value

+ -

For Container, returns the value at the given indices or (if not +

For Container, returns the value at the given indices or (if not found) the given default value.

+ +

For dict.table, returns the columns at the given indices or (if not found) columns with the given default value.

-

Details

- +
+
+

Details

peek_at tries to access specific values.

-

See also

- -

at() for strict element extraction

+
+
+

See also

+

at() for strict element extraction

+
-

Examples

-
-# Container -co = container(a = 1, 2, b = 3, 4) -peek_at(co, 1) -
#> [a = 1]
peek_at(co, "a") -
#> [a = 1]
peek_at(co, "x") -
#> []
peek_at(co, "x", .default = 0) -
#> [x = 0]
peek_at(co, "a", "x", 2, 9, .default = -1) -
#> [a = 1, x = -1, 2, -1]
-# Dict -d = dict(a = 1, b = 1:3) -peek_at(d, "b") -
#> {b = (1L 2L 3L)}
peek_at(d, "x") -
#> {}
peek_at(d, "x", .default = 4:7) -
#> {x = (4L 5L 6L 7L)}
-# dict.table -dit = dict.table(a = 1:3, b = 4:6) -peek_at(dit, "a") -
#> <dict.table> with 3 rows and 1 column -#> a -#> 1: 1 -#> 2: 2 -#> 3: 3
peek_at(dit, 1) -
#> <dict.table> with 3 rows and 1 column -#> a -#> 1: 1 -#> 2: 2 -#> 3: 3
peek_at(dit, 3) -
#> <dict.table> with 0 rows and 0 columns -#> Null data.table (0 rows and 0 cols)
peek_at(dit, "x") -
#> <dict.table> with 0 rows and 0 columns -#> Null data.table (0 rows and 0 cols)
peek_at(dit, "x", .default = 0) -
#> <dict.table> with 3 rows and 1 column -#> x -#> 1: 0 -#> 2: 0 -#> 3: 0
peek_at(dit, "a", "x", .default = 0) -
#> <dict.table> with 3 rows and 2 columns -#> a x -#> 1: 1 0 -#> 2: 2 0 -#> 3: 3 0
+
+

Examples

+

+# Container
+co = container(a = 1, 2, b = 3, 4)
+peek_at(co, 1)
+#> [a = 1]
+peek_at(co, "a")
+#> [a = 1]
+peek_at(co, "x")
+#> []
+peek_at(co, "x", .default = 0)
+#> [x = 0]
+peek_at(co, "a", "x", 2, 9, .default = -1)
+#> [a = 1, x = -1, 2, -1]
+
+# Dict
+d = dict(a = 1, b = 1:3)
+peek_at(d, "b")
+#> {b = (1L 2L 3L)}
+peek_at(d, "x")
+#> {}
+peek_at(d, "x", .default = 4:7)
+#> {x = (4L 5L 6L 7L)}
+
+# dict.table
+dit = dict.table(a = 1:3, b = 4:6)
+peek_at(dit, "a")
+#> <dict.table> with 3 rows and 1 column
+#>    a
+#> 1: 1
+#> 2: 2
+#> 3: 3
+peek_at(dit, 1)
+#> <dict.table> with 3 rows and 1 column
+#>    a
+#> 1: 1
+#> 2: 2
+#> 3: 3
+peek_at(dit, 3)
+#> <dict.table> with 0 rows and 0 columns
+#> Null data.table (0 rows and 0 cols)
+peek_at(dit, "x")
+#> <dict.table> with 0 rows and 0 columns
+#> Null data.table (0 rows and 0 cols)
+peek_at(dit, "x", .default = 0)
+#> <dict.table> with 3 rows and 1 column
+#>    x
+#> 1: 0
+#> 2: 0
+#> 3: 0
+peek_at(dit, "a", "x", .default = 0)
+#> <dict.table> with 3 rows and 2 columns
+#>    a x
+#> 1: 1 0
+#> 2: 2 0
+#> 3: 3 0
+
+
+
- - - + + diff --git a/docs/reference/peek_at2.html b/docs/reference/peek_at2.html index eb535c75..a2743fb8 100644 --- a/docs/reference/peek_at2.html +++ b/docs/reference/peek_at2.html @@ -1,77 +1,14 @@ - - - - - - - -Peek at Single Index — peek_at2 • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Peek at Single Index — peek_at2 • container - - - - - - - - - - - + + - - - -
-
- -
- -
+
@@ -205,93 +131,109 @@

Peek at Single Index

access, that is, it remains valid even if peeked elements don't exist.

-
peek_at2(x, index, default = NULL)
+    
+
peek_at2(x, index, default = NULL)
+
+# S3 method for Container
+peek_at2(x, index, default = NULL)
+
+# S3 method for dict.table
+peek_at2(x, index, default = NULL)
+
+ +
+

Arguments

+
x
+

an R object of the respective class.

-# S3 method for Container -peek_at2(x, index, default = NULL) -# S3 method for dict.table -peek_at2(x, index, default = NULL)
+
index
+

character name or numeric position of the sought value.

-

Arguments

- - - - - - - - - - - - - - -
x

an R object of the respective class.

index

character name or numeric position of the sought value.

default

value to be returned if peeked value does not exist.

-

Value

+
default
+

value to be returned if peeked value does not exist.

-

For Container, returns the value at the given index or (if not +

+
+

Value

+ + +

For Container, returns the value at the given index or (if not found) the given default value.

+ +

For dict.table, returns the column named index if it exist otherwise the given default value. If the default length does not match the number of rows, it is recycled accordingly and a warning is given, unless the default value has a length of 1, in which case recycling is done silently.

-

See also

- -

at2() for strict element extraction

+
+
+

See also

+

at2() for strict element extraction

+
-

Examples

-
-# Container -co = container(a = 1, 2, b = 3, 4) -peek_at2(co, 1) -
#> [1] 1
peek_at2(co, "a") -
#> [1] 1
peek_at2(co, "x") -
#> NULL
peek_at2(co, "x", default = 0) -
#> [1] 0
-# Dict -d = dict(a = 1, b = 1:3) -peek_at2(d, "b") -
#> [1] 1 2 3
peek_at2(d, "x") -
#> NULL
peek_at2(d, "x", default = 4:7) -
#> [1] 4 5 6 7
-# dict.table -dit = dict.table(a = 1:3, b = 4:6) -peek_at2(dit, "a") -
#> [1] 1 2 3
peek_at2(dit, 1) -
#> [1] 1 2 3
peek_at2(dit, 3) -
#> NULL
peek_at2(dit, 3, default = 9) -
#> [1] 9 9 9
peek_at2(dit, "x") -
#> NULL
peek_at2(dit, "x", default = 0) -
#> [1] 0 0 0
+
+

Examples

+

+# Container
+co = container(a = 1, 2, b = 3, 4)
+peek_at2(co, 1)
+#> [1] 1
+peek_at2(co, "a")
+#> [1] 1
+peek_at2(co, "x")
+#> NULL
+peek_at2(co, "x", default = 0)
+#> [1] 0
+
+# Dict
+d = dict(a = 1, b = 1:3)
+peek_at2(d, "b")
+#> [1] 1 2 3
+peek_at2(d, "x")
+#> NULL
+peek_at2(d, "x", default = 4:7)
+#> [1] 4 5 6 7
+
+# dict.table
+dit = dict.table(a = 1:3, b = 4:6)
+peek_at2(dit, "a")
+#> [1] 1 2 3
+peek_at2(dit, 1)
+#> [1] 1 2 3
+peek_at2(dit, 3)
+#> NULL
+peek_at2(dit, 3, default = 9)
+#> [1] 9 9 9
+peek_at2(dit, "x")
+#> NULL
+peek_at2(dit, "x", default = 0)
+#> [1] 0 0 0
+
+
+
- - - + + diff --git a/docs/reference/pop.html b/docs/reference/pop.html index 2f26e67f..e41904ef 100644 --- a/docs/reference/pop.html +++ b/docs/reference/pop.html @@ -1,76 +1,13 @@ - - - - - - - -Get and Remove Element — pop • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Get and Remove Element — pop • container - - - - + + -
-
- -
- -
+
@@ -203,109 +129,124 @@

Get and Remove Element

If the element is not found, signal an error.

-
ref_pop(.x, ...)
-
-ref_popleft(.x, ...)
+    
+
ref_pop(.x, ...)
+
+ref_popleft(.x, ...)
+
+# S3 method for Deque
+ref_pop(.x, ...)
+
+# S3 method for Deque
+ref_popleft(.x, ...)
+
+# S3 method for Container
+ref_pop(.x, index, ...)
+
+# S3 method for dict.table
+ref_pop(.x, index, ...)
+
-# S3 method for Deque -ref_pop(.x, ...) +
+

Arguments

+
.x
+

any R object.

-# S3 method for Deque -ref_popleft(.x, ...) -# S3 method for Container -ref_pop(.x, index, ...) +
...
+

additional arguments to be passed to or from methods.

-# S3 method for dict.table -ref_pop(.x, index, ...)
-

Arguments

- - - - - - - - - - - - - - -
.x

any R object.

...

additional arguments to be passed to or from methods.

index

character name or numeric position of value to be popped

+
index
+

character name or numeric position of value to be popped

-

Value

+
+
+

Value

+ -

For Deque the first (ref_popleft) or last (ref_pop) element of +

For Deque the first (ref_popleft) or last (ref_pop) element of the deque after it was removed.

+ +

For Container the value at the given index after it was removed from the Container object. If index is not found, an error is raised.

+ +

For dict.table, returns the column at the given index after it was removed from the dict.table. If column does not exist, an error is raised.

-

Details

- +
+
+

Details

All functions work by reference, that is, the original object is altered. ref_pop(.x) tries to access specific values.

ref_popleft(.x) pops first element of a Deque.

-

See also

- - - -

Examples

-
# Deque -d = deque(1, 2, 3) -ref_pop(d) -
#> [1] 3
ref_popleft(d) -
#> [1] 1
-if (FALSE) { -ref_pop(deque()) # pop at empty Deque -} - -# Container -co = container(a = 1, b = 1:3, d = "foo") -ref_pop(co, "b") -
#> [1] 1 2 3
ref_pop(co, 1) -
#> [1] 1
-if (FALSE) { -ref_pop(co, "x") # index 'x' not found -} +
+
+

See also

+ +
-# dict.table -dit = dict.table(a = 1:3, b = 4:6) -ref_pop(dit, "a") -
#> [1] 1 2 3
ref_pop(dit, 1) -
#> [1] 4 5 6
-if (FALSE) { -ref_pop(dit, "x") # index 'x' not found -} -
+
+

Examples

+
# Deque
+d = deque(1, 2, 3)
+ref_pop(d)
+#> [1] 3
+ref_popleft(d)
+#> [1] 1
+
+try({
+ref_pop(deque())  # pop at empty Deque
+})
+#> Error : pop at empty Deque
+
+# Container
+co = container(a = 1, b = 1:3, d = "foo")
+ref_pop(co, "b")
+#> [1] 1 2 3
+ref_pop(co, 1)
+#> [1] 1
+
+try({
+ref_pop(co, "x")  # index 'x' not found
+})
+#> Error : index 'x' not found
+
+# dict.table
+dit = dict.table(a = 1:3, b = 4:6)
+ref_pop(dit, "a")
+#> [1] 1 2 3
+ref_pop(dit, 1)
+#> [1] 4 5 6
+
+try({
+ref_pop(dit, "x")  # index 'x' not found
+})
+#> Error : index 'x' not found
+
+
+
- - - + + diff --git a/docs/reference/rename.html b/docs/reference/rename.html index 1b0148cf..9df04642 100644 --- a/docs/reference/rename.html +++ b/docs/reference/rename.html @@ -1,77 +1,14 @@ - - - - - - - -Rename Elements Safely — rename • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Rename Elements Safely — rename • container - - - - - - - - - - - + + - - - -
-
- -
- -
+
@@ -205,101 +131,113 @@

Rename Elements Safely

already existing name, an error is signaled.

-
rename(.x, old, new)
-
-ref_rename(.x, old, new)
+    
+
rename(.x, old, new)
+
+ref_rename(.x, old, new)
+
+# S3 method for Container
+rename(.x, old, new)
+
+# S3 method for dict.table
+rename(.x, old, new)
+
+# S3 method for dict.table
+ref_rename(.x, old, new)
+
+# S3 method for default
+rename(.x, old, new)
+
-# S3 method for Container -rename(.x, old, new) +
+

Arguments

+
.x
+

dict.table object

-# S3 method for dict.table -rename(.x, old, new) -# S3 method for dict.table -ref_rename(.x, old, new) +
old
+

character old name

-# S3 method for default -rename(.x, old, new)
-

Arguments

- - - - - - - - - - - - - - -
.x

dict.table object

old

character old name

new

character new name

+
new
+

character new name

-

Value

+
+
+

Value

+ -

For standard R vectors renames old to new and returns the +

For standard R vectors renames old to new and returns the renamed vector.

+ +

For Container, an object of class Container (or one of the respective derived classes).

-

For dict.table renames key old to new in place (i.e. by -reference) and invisibly returns the dict.table() object.

-

Details

+ +

For dict.table renames key old to new in place (i.e. by +reference) and invisibly returns the dict.table() object.

+
+
+

Details

The passed old and new names can be vectors but always must have the same length and must be unique to prevent double-renaming.

rename uses copy semantics while ref_rename works by reference, that is, it renames elements in place.

+
-

Examples

-
-# Container -co = container(a = 1, b = 2, 3) -rename(co, c("a", "b"), c("a1", "y")) -
#> [a1 = 1, y = 2, 3]
print(co) -
#> [a = 1, b = 2, 3]
ref_rename(co, c("a", "b"), c("a1", "y")) -
#> [a1 = 1, y = 2, 3]
print(co) -
#> [a1 = 1, y = 2, 3]
-# dict.table -dit = dict.table(a = 1, b = 2, c = 3) -rename(dit, c("a", "b"), c("a1", "y")) -
#> <dict.table> with 1 row and 3 columns -#> a1 y c -#> 1: 1 2 3
print(dit) -
#> <dict.table> with 1 row and 3 columns -#> a b c -#> 1: 1 2 3
ref_rename(dit, c("a", "b"), c("a1", "y")) -print(dit) -
#> <dict.table> with 1 row and 3 columns -#> a1 y c -#> 1: 1 2 3
+
+

Examples

+

+# Container
+co = container(a = 1, b = 2, 3)
+rename(co, c("a", "b"), c("a1", "y"))
+#> [a1 = 1, y = 2, 3]
+print(co)
+#> [a = 1, b = 2, 3]
+ref_rename(co, c("a", "b"), c("a1", "y"))
+#> [a1 = 1, y = 2, 3]
+print(co)
+#> [a1 = 1, y = 2, 3]
+
+# dict.table
+dit = dict.table(a = 1, b = 2, c = 3)
+rename(dit, c("a", "b"), c("a1", "y"))
+#> <dict.table> with 1 row and 3 columns
+#>    a1 y c
+#> 1:  1 2 3
+print(dit)
+#> <dict.table> with 1 row and 3 columns
+#>    a b c
+#> 1: 1 2 3
+ref_rename(dit, c("a", "b"), c("a1", "y"))
+print(dit)
+#> <dict.table> with 1 row and 3 columns
+#>    a1 y c
+#> 1:  1 2 3
+
+
+
- - - + + diff --git a/docs/reference/replace.html b/docs/reference/replace.html index 0e480862..710a7f89 100644 --- a/docs/reference/replace.html +++ b/docs/reference/replace.html @@ -1,76 +1,13 @@ - - - - - - - -Replace Values in Containers Safely — replace • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Replace Values in Containers Safely — replace • container - - + + - - -
-
- -
- -
+
@@ -203,103 +129,113 @@

Replace Values in Containers Safely

found, unless it is stated to explicitly add the element (see option add).

-
replace(.x, ...)
+    
+
replace(.x, ...)
+
+ref_replace(.x, ...)
+
+# S3 method for Container
+replace(.x, old, new, add = FALSE, ...)
+
+# S3 method for Container
+ref_replace(.x, old, new, add = FALSE, ...)
+
+# S3 method for Dict
+replace(.x, old, new, ...)
+
+# S3 method for Dict
+ref_replace(.x, old, new, ...)
+
+ +
+

Arguments

+
.x
+

any R object.

+ -ref_replace(.x, ...) +
...
+

additional arguments to be passed to or from methods.

-# S3 method for Container -replace(.x, old, new, add = FALSE, ...) -# S3 method for Container -ref_replace(.x, old, new, add = FALSE, ...) +
old
+

old element to be found and replaced.

-# S3 method for Dict -replace(.x, old, new, ...) -# S3 method for Dict -ref_replace(.x, old, new, ...)
+
new
+

the new element replacing the old one.

-

Arguments

- - - - - - - - - - - - - - - - - - - - - - -
.x

any R object.

...

additional arguments to be passed to or from methods.

old

old element to be found and replaced.

new

the new element replacing the old one.

add

logical if FALSE (default) and element was not found, + +

add
+

logical if FALSE (default) and element was not found, an error is given. In contrast, if set to TRUE the new element is added regardless of whether it is used as a replacement for an existing element or -just added as a new element.

+just added as a new element.

-

Value

+
+
+

Value

+ -

For Container, an object of class Container (or one of the +

For Container, an object of class Container (or one of the respective derived classes).

-

For Dict an object of class Dict.

-

Details

-

replace uses copy semantics while ref_replace works by reference.

-

Examples

-
-co = container("x", 9) -replace(co, 9, 0) -
#> ["x", 0]
replace(co, "x", 0) -
#> [0, 9]
if (FALSE) { -replace(co, "z", 0) # old element ("z") is not in Container -} -replace(co, "z", 0, add = TRUE) # just add the zero without replacement -
#> ["x", 9, 0]
+

For Dict an object of class Dict.

+
+
+

Details

+

replace uses copy semantics while ref_replace works by reference.

+
-d = dict(a = 1, b = "z") -replace(d, 1, 1:5) -
#> {a = (1L 2L 3L 4L ...), b = "z"}
replace(d, "z", "a") -
#> {a = 1, b = "a"}
-if (FALSE) { -replace(d, "a", 2) # old element ("a") is not in Dict -} -
+
+

Examples

+

+co = container("x", 9)
+replace(co, 9, 0)
+#> ["x", 0]
+replace(co, "x", 0)
+#> [0, 9]
+try({
+replace(co, "z", 0)              # old element ("z") is not in Container
+})
+#> Error : old element ("z") is not in Container
+replace(co, "z", 0, add = TRUE)  # just add the zero without replacement
+#> ["x", 9, 0]
+
+
+d = dict(a = 1, b = "z")
+replace(d, 1, 1:5)
+#> {a = (1L 2L 3L 4L ...), b = "z"}
+replace(d, "z", "a")
+#> {a = 1, b = "a"}
+
+try({
+replace(d, "a", 2)              # old element ("a") is not in Dict
+})
+#> Error : old element ("a") is not in Dict
+
+
+
- - - + + diff --git a/docs/reference/replace_at.html b/docs/reference/replace_at.html index f0d6ffbe..7601fcbc 100644 --- a/docs/reference/replace_at.html +++ b/docs/reference/replace_at.html @@ -1,77 +1,14 @@ - - - - - - - -Replace Values at Indices Safely — replace_at • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Replace Values at Indices Safely — replace_at • container - - - - - - - - - - - + + - - - -
-
- -
- -
+
@@ -205,128 +131,143 @@

Replace Values at Indices Safely

option add).

-
replace_at(.x, ...)
-
-ref_replace_at(.x, ...)
+    
+
replace_at(.x, ...)
+
+ref_replace_at(.x, ...)
+
+# S3 method for Container
+replace_at(.x, ..., .add = FALSE)
+
+# S3 method for Container
+ref_replace_at(.x, ..., .add = FALSE)
+
+# S3 method for dict.table
+replace_at(.x, ..., .add = FALSE)
+
+# S3 method for dict.table
+ref_replace_at(.x, ..., .add = FALSE)
+
-# S3 method for Container -replace_at(.x, ..., .add = FALSE) +
+

Arguments

+
.x
+

any R object.

-# S3 method for Container -ref_replace_at(.x, ..., .add = FALSE) -# S3 method for dict.table -replace_at(.x, ..., .add = FALSE) +
...
+

either name = value pairs or two vectors/lists with names/values +to be replaced.

-# S3 method for dict.table -ref_replace_at(.x, ..., .add = FALSE)
-

Arguments

- - - - - - - - - - - - - - -
.x

any R object.

...

either name = value pairs or two vectors/lists with names/values -to be replaced.

.add

logical if FALSE (default) and index is invalid, an error is +

.add
+

logical if FALSE (default) and index is invalid, an error is given. If set to TRUE the new element is added at the given index regardless whether the index existed or not. Indices can consist of numbers or names or both, except when adding values at new indices, which is only -allowed for names.

+allowed for names.

-

Value

+
+
+

Value

+ -

For Container, an object of class Container (or one of the +

For Container, an object of class Container (or one of the respective derived classes).

-

For dict.table an object of class dict.table.

-

Details

+ +

For dict.table an object of class dict.table.

+
+
+

Details

replace_at uses copy semantics while ref_replace_at works by reference.

+
-

Examples

-
-co = container(a = 0, b = "z") -replace_at(co, a = 1, b = 2) -
#> [a = 1, b = 2]
replace_at(co, 1:2, 1:2) # same -
#> [a = 1L, b = 2L]
replace_at(co, c("a", "b"), list(1, 2)) # same -
#> [a = 1, b = 2]
-if (FALSE) { -replace_at(co, x = 1) # names(s) not found: 'x' -} -replace_at(co, x = 1, .add = TRUE) # ok (adds x = 1) -
#> [a = 0, b = "z", x = 1]
- -dit = dict.table(a = 1:3, b = 4:6) -replace_at(dit, a = 3:1) -
#> <dict.table> with 3 rows and 2 columns -#> a b -#> 1: 3 4 -#> 2: 2 5 -#> 3: 1 6
replace_at(dit, 1, 3:1) # same -
#> <dict.table> with 3 rows and 2 columns -#> a b -#> 1: 3 4 -#> 2: 2 5 -#> 3: 1 6
replace_at(dit, "a", 3:1) # same -
#> <dict.table> with 3 rows and 2 columns -#> a b -#> 1: 3 4 -#> 2: 2 5 -#> 3: 1 6
replace_at(dit, a = 3:1, b = 6:4) -
#> <dict.table> with 3 rows and 2 columns -#> a b -#> 1: 3 6 -#> 2: 2 5 -#> 3: 1 4
replace_at(dit, 1:2, list(3:1, 6:4)) # same -
#> <dict.table> with 3 rows and 2 columns -#> a b -#> 1: 3 6 -#> 2: 2 5 -#> 3: 1 4
-if (FALSE) { -replace_at(dit, x = 1) # column(s) not found: 'x' -} -replace_at(dit, x = 1, .add = TRUE) # ok (adds column) -
#> <dict.table> with 3 rows and 3 columns -#> a b x -#> 1: 1 4 1 -#> 2: 2 5 1 -#> 3: 3 6 1
+
+

Examples

+

+co = container(a = 0, b = "z")
+replace_at(co, a = 1, b = 2)
+#> [a = 1, b = 2]
+replace_at(co, 1:2, 1:2)                 # same
+#> [a = 1L, b = 2L]
+replace_at(co, c("a", "b"), list(1, 2))  # same
+#> [a = 1, b = 2]
+
+try({
+replace_at(co, x = 1)                    # names(s) not found: 'x'
+})
+#> Error : names(s) not found: 'x'
+replace_at(co, x = 1, .add = TRUE)       # ok (adds x = 1)
+#> [a = 0, b = "z", x = 1]
+
+
+dit = dict.table(a = 1:3, b = 4:6)
+replace_at(dit, a = 3:1)
+#> <dict.table> with 3 rows and 2 columns
+#>    a b
+#> 1: 3 4
+#> 2: 2 5
+#> 3: 1 6
+replace_at(dit, 1, 3:1)                  # same
+#> <dict.table> with 3 rows and 2 columns
+#>    a b
+#> 1: 3 4
+#> 2: 2 5
+#> 3: 1 6
+replace_at(dit, "a", 3:1)                # same
+#> <dict.table> with 3 rows and 2 columns
+#>    a b
+#> 1: 3 4
+#> 2: 2 5
+#> 3: 1 6
+replace_at(dit, a = 3:1, b = 6:4)
+#> <dict.table> with 3 rows and 2 columns
+#>    a b
+#> 1: 3 6
+#> 2: 2 5
+#> 3: 1 4
+replace_at(dit, 1:2, list(3:1, 6:4))     # same
+#> <dict.table> with 3 rows and 2 columns
+#>    a b
+#> 1: 3 6
+#> 2: 2 5
+#> 3: 1 4
+
+try({
+replace_at(dit, x = 1)                   # column(s) not found: 'x'
+})
+#> Error : column(s) not found: 'x'
+replace_at(dit, x = 1, .add = TRUE)      # ok (adds column)
+#> <dict.table> with 3 rows and 3 columns
+#>    a b x
+#> 1: 1 4 1
+#> 2: 2 5 1
+#> 3: 3 6 1
+
+
+
- - - + + diff --git a/docs/reference/rev.html b/docs/reference/rev.html index 3e551937..8423524a 100644 --- a/docs/reference/rev.html +++ b/docs/reference/rev.html @@ -1,75 +1,12 @@ - - - - - - - -Reverse Elements — rev • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Reverse Elements — rev • container + + - - - - -
-
- -
- -
+
@@ -201,68 +127,76 @@

Reverse Elements

rev provides a reversed version of its argument.

-
ref_rev(x)
-
-# S3 method for Deque
-ref_rev(x)
+    
+
ref_rev(x)
+
+# S3 method for Deque
+ref_rev(x)
+
+# S3 method for Deque
+rev(x)
+
-# S3 method for Deque -rev(x)
+
+

Arguments

+
x
+

Deque object

-

Arguments

- - - - - - -
x

Deque object

+
+
+

Value

+ -

Value

+

For Deque, an object of class Deque

-

For Deque, an object of class Deque

-

Details

+
+
+

Details

rev uses copy semantics while ref_rev works by reference, that is, it reverse all elements in place.

-

See also

- - +
+
+

See also

+ +
-

Examples

-
-d = deque(a = 1, b = 2, 3) -rev(d) -
#> |3, b = 2, a = 1|
print(d) -
#> |a = 1, b = 2, 3|
ref_rev(d) -
#> |3, b = 2, a = 1|
print(d) -
#> |3, b = 2, a = 1|
-
+
+

Examples

+

+d = deque(a = 1, b = 2, 3)
+rev(d)
+#> |3, b = 2, a = 1|
+print(d)
+#> |a = 1, b = 2, 3|
+ref_rev(d)
+#> |3, b = 2, a = 1|
+print(d)
+#> |3, b = 2, a = 1|
+
+
+
+
- - - + + diff --git a/docs/reference/rotate.html b/docs/reference/rotate.html index 52d1a00e..e5ce6623 100644 --- a/docs/reference/rotate.html +++ b/docs/reference/rotate.html @@ -1,76 +1,13 @@ - - - - - - - -Rotate Elements — rotate • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Rotate Elements — rotate • container - - + + - - -
-
- -
- -
+
@@ -203,67 +129,70 @@

Rotate Elements

negative, rotate to the left.

-
rotate(x, n = 1L)
-
-ref_rotate(x, n = 1L)
-
-# S3 method for Deque
-rotate(x, n = 1L)
+    
+
rotate(x, n = 1L)
+
+ref_rotate(x, n = 1L)
+
+# S3 method for Deque
+rotate(x, n = 1L)
+
+# S3 method for Deque
+ref_rotate(x, n = 1L)
+
-# S3 method for Deque -ref_rotate(x, n = 1L)
+
+

Arguments

+
x
+

any R object.

-

Arguments

- - - - - - - - - - -
x

any R object.

n

integer number of steps to rotate

-

Value

+
n
+

integer number of steps to rotate

-

For Deque returns the rotated Deque() object.

-

Details

+
+
+

Value

+ +

For Deque returns the rotated Deque() object.

+
+
+

Details

While rotate uses copy semantics, ref_rotate works by reference, that is, rotates in place on the original object.

+
-

Examples

-
d = deque(1, 2, 3, 4) -rotate(d) -
#> |4, 1, 2, 3|
rotate(d, n = 2) -
#> |3, 4, 1, 2|
+
+

Examples

+
d = deque(1, 2, 3, 4)
+rotate(d)
+#> |4, 1, 2, 3|
+rotate(d, n = 2)
+#> |3, 4, 1, 2|
+
+
+
- - - + + diff --git a/docs/reference/setS3.html b/docs/reference/setS3.html index df94d71e..5ca9ee9e 100644 --- a/docs/reference/setS3.html +++ b/docs/reference/setS3.html @@ -1,77 +1,14 @@ - - - - - - - -Set and ordered Set — SetS3 • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Set and ordered Set — SetS3 • container - - - - - - - - - - - - + + - - -
-
- -
- -
+
-

The Set is considered and implemented as a specialized -Container, that is, Set elements are always unique. It provides +

The Set is considered and implemented as a specialized +Container, that is, Set elements are always unique. It provides typical set operations such as union and intersect.

-
setnew(..., .ordered = FALSE)
-
-as.set(x)
+    
+
setnew(..., .ordered = FALSE)
+
+as.set(x)
+
+as.orderedset(x)
+
+is.set(x)
+
+is.orderedset(x)
+
-as.orderedset(x) +
+

Arguments

+
...
+

initial elements put into the Set.

-is.set(x) -is.orderedset(x)
+
.ordered
+

logical if TRUE all elements in the Set will be +ordered.

-

Arguments

- - - - - - - - - - - - - - -
...

initial elements put into the Set.

.ordered

logical if TRUE all elements in the Set will be -ordered.

x

R object of ANY type for as.set() and is.set() -or of class Set for the S3 methods.

-

Details

+
x
+

R object of ANY type for as.set() and is.set() +or of class Set for the S3 methods.

-

Methods that alter Set objects usually come in two versions +

+
+

Details

+

Methods that alter Set objects usually come in two versions providing either copy or reference semantics where the latter start with -'ref_' to note the reference semantic, for example, add() and ref_add().

-
    -
  • setnew(...) initializes and returns a Set() object.

  • -
- -
    -
  • as.set(x) coerces x to a set.

  • -
- -
    -
  • as.orderedset(x) coerces x to an ordered set.

  • -
- -
    -
  • is.set(x) returns TRUE if x is of class Set and FALSE +'ref_' to note the reference semantic, for example, add() and ref_add().

    +
    • setnew(...) initializes and returns a Set() object.

    • +
    • as.set(x) coerces x to a set.

    • +
    • as.orderedset(x) coerces x to an ordered set.

    • +
    • is.set(x) returns TRUE if x is of class Set and FALSE otherwise.

    • -
    - -
      -
    • is.orderedset(x) returns TRUE if x is of class OrderedSet +

    • is.orderedset(x) returns TRUE if x is of class OrderedSet and FALSE otherwise.

    • -
    - -
      -
    • x & y performs the set intersection of x and y

    • -
    - -
      -
    • x | y performs the set union of x and y

    • -
    - -

    See also

    - -

    See container() for all inherited methods. For the full class -documentation see Set and it's superclass Container.

    +
  • x & y performs the set intersection of x and y

  • +
  • x | y performs the set union of x and y

  • +
+
+

See also

+

See container() for all inherited methods. For the full class +documentation see Set and it's superclass Container.

+
-

Examples

-
s = setnew(1, b = NA, 1:3, c = container("a", 1)) -is.set(s) -
#> [1] TRUE
print(s) -
#> {1, b = NA, (1L 2L 3L), c = ["a", 1]}
length(s) -
#> [1] 4
names(s) -
#> [1] "" "b" "" "c"
as.list(s) -
#> [[1]] -#> [1] 1 -#> -#> $b -#> [1] NA -#> -#> [[3]] -#> [1] 1 2 3 -#> -#> $c -#> ["a", 1] -#>
unpack(s) # flatten recursively similar to unlist -
#> b c1 c2 -#> "1" NA "1" "2" "3" "a" "1"
-so = setnew(2, 1, .ordered = TRUE) -print(so) -
#> {1, 2}
add(so, 0) -
#> {0, 1, 2}
# Math -s = setnew(5:3, 1, 2) -s -
#> {(5L 4L 3L), 1, 2}
abs(s) -
#> {5, 4, 3, 1, 2}
cumsum(s) -
#> {5, 9, 12, 13, 15}
round(s) -
#> {5, 4, 3, 1, 2}
exp(s) -
#> {148.4132, 54.59815, 20.08554, 2.718282, 7.389056}
-# Summary -range(s) -
#> [1] 1 5
min(s) -
#> [1] 1
max(s) -
#> [1] 5
-s1 = setnew(1, 1:2) -s2 = setnew(2, 1:2) -s1 + s2 # same as s1 | s2 or c(c1, s2) -
#> {1, (1L 2L), 2}
s2 + s1 # same -
#> {2, (1L 2L), 1}
-s1 - s2 -
#> {1}
s2 - s1 -
#> {2}
-s1 = setnew(1, b = 2) -s2 = setnew(1, b = 4) -s1 & s2 # {1} -
#> {1}
-s1 | s2 # {1, b = 2, b = 4} -
#> {1, b = 2, b = 4}
-
+
+

Examples

+
s = setnew(1, b = NA, 1:3, c = container("a", 1))
+is.set(s)
+#> [1] TRUE
+print(s)
+#> {1, b = NA, (1L 2L 3L), c = ["a", 1]}
+length(s)
+#> [1] 4
+names(s)
+#> [1] ""  "b" ""  "c"
+as.list(s)
+#> [[1]]
+#> [1] 1
+#> 
+#> $b
+#> [1] NA
+#> 
+#> [[3]]
+#> [1] 1 2 3
+#> 
+#> $c
+#> ["a", 1]
+#> 
+unpack(s)   # flatten recursively similar to unlist
+#>       b              c1  c2 
+#> "1"  NA "1" "2" "3" "a" "1" 
+
+so = setnew(2, 1, .ordered = TRUE)
+print(so)
+#> {1, 2}
+add(so, 0)
+#> {0, 1, 2}
+# Math
+s = setnew(5:3, 1, 2)
+s
+#> {(5L 4L 3L), 1, 2}
+abs(s)
+#> {5, 4, 3, 1, 2}
+cumsum(s)
+#> {5, 9, 12, 13, 15}
+round(s)
+#> {5, 4, 3, 1, 2}
+exp(s)
+#> {148.4132, 54.59815, 20.08554, 2.718282, 7.389056}
+
+# Summary
+range(s)
+#> [1] 1 5
+min(s)
+#> [1] 1
+max(s)
+#> [1] 5
+
+s1 = setnew(1, 1:2)
+s2 = setnew(2, 1:2)
+s1 + s2     # same as s1 | s2 or c(c1, s2)
+#> {1, (1L 2L), 2}
+s2 + s1     # same
+#> {2, (1L 2L), 1}
+
+s1 - s2
+#> {1}
+s2 - s1
+#> {2}
+
+s1 = setnew(1, b = 2)
+s2 = setnew(1, b = 4)
+s1 & s2     # {1}
+#> {1}
+
+s1 | s2     # {1, b = 2, b = 4}
+#> {1, b = 2, b = 4}
+
+
+
+
- - - + + diff --git a/docs/reference/unpack.html b/docs/reference/unpack.html index 75c67933..0712af5b 100644 --- a/docs/reference/unpack.html +++ b/docs/reference/unpack.html @@ -1,78 +1,15 @@ - - - - - - - -Unpack Nested Objects — unpack • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Unpack Nested Objects — unpack • container - - - - - - - - - - + + - - - - -
-
- -
- -
+
-

Similary to unlist() recursively unpacks any (possibly nested) structure -into a flat list. In contrast to unlist(), unpack() also works with -(possibly nested) Container() objects. In principle, it works for any +

Similary to unlist() recursively unpacks any (possibly nested) structure +into a flat list. In contrast to unlist(), unpack() also works with +(possibly nested) Container() objects. In principle, it works for any object that can be transformed to a list via as.list.

-
unpack(x, recursive = TRUE, use.names = TRUE)
+
+
unpack(x, recursive = TRUE, use.names = TRUE)
+
-

Arguments

- - - - - - - - - - - - - - -
x

any R object

recursive

logical descend recursively into nested objects?

use.names

logical Should names be preserved?

+
+

Arguments

+
x
+

any R object

-

Value

-

a list

+
recursive
+

logical descend recursively into nested objects?

+ + +
use.names
+

logical Should names be preserved?

+ +
+
+

Value

+ + +

a list

+ + +
+
-
- - + + diff --git a/docs/reference/update.html b/docs/reference/update.html index 6f7926d8..01aa52ac 100644 --- a/docs/reference/update.html +++ b/docs/reference/update.html @@ -1,77 +1,14 @@ - - - - - - - -Update Object with Elements from Another Object — update • container - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Update Object with Elements from Another Object — update • container - - - - - - - - - - - + + - - - -
-
- -
- -
+
@@ -205,109 +131,120 @@

Update Object with Elements from Another Object

the other object. A common use case is to update parameter lists.

-
ref_update(object, other, ...)
-
-# S3 method for Container
-update(object, other, ...)
+    
+
ref_update(object, other, ...)
+
+# S3 method for Container
+update(object, other, ...)
+
+# S3 method for Container
+ref_update(object, other, ...)
+
+# S3 method for dict.table
+update(object, other, ...)
+
+# S3 method for dict.table
+ref_update(object, other, ...)
+
+# S3 method for list
+update(object, other, ...)
+
-# S3 method for Container -ref_update(object, other, ...) +
+

Arguments

+
object
+

any R object

-# S3 method for dict.table -update(object, other, ...) -# S3 method for dict.table -ref_update(object, other, ...) +
other
+

any object of the same type as object

-# S3 method for list -update(object, other, ...)
-

Arguments

- - - - - - - - - - - - - - -
object

any R object

other

any object of the same type as object

...

additional arguments to be passed to or from methods.

+
...
+

additional arguments to be passed to or from methods.

-

Value

+
+
+

Value

+ -

For Container, an object of class Container (or one of the +

For Container, an object of class Container (or one of the respective derived classes).

+ +

For dict.table an object of class dict.table.

-

For list, an updated object of class list.

-

Details

+ +

For list, an updated object of class list.

+
+
+

Details

update uses copy semantics while ref_update works by reference, that is, updates in place.

+
-

Examples

-
-d1 = dict(a = 1, b = 2) -d2 = dict( b = 0, c = 3) -update(d1, d2) # {a = 1, b = 0, c = 3} -
#> {a = 1, b = 0, c = 3}
update(d2, d1) # {a = 1, b = 2, c = 3} -
#> {a = 1, b = 2, c = 3}
-dit1 = dict.table(a = 1:2, b = 3:4) -dit2 = dict.table( b = 5:6, c = 8:9) -update(d1, d2) -
#> {a = 1, b = 0, c = 3}
update(d2, d1) -
#> {a = 1, b = 2, c = 3}
-l1 = list(1, b = 2) -l2 = list( b = 0, c = 3) -update(l1, l2) -
#> [[1]] -#> [1] 1 -#> -#> $b -#> [1] 0 -#> -#> $c -#> [1] 3 -#>
update(l2, l1) -
#> $b -#> [1] 2 -#> -#> $c -#> [1] 3 -#> -#> [[3]] -#> [1] 1 -#>
+
+

Examples

+

+d1 = dict(a = 1, b = 2)
+d2 = dict(       b = 0, c = 3)
+update(d1, d2)  # {a = 1, b = 0, c = 3}
+#> {a = 1, b = 0, c = 3}
+update(d2, d1)  # {a = 1, b = 2, c = 3}
+#> {a = 1, b = 2, c = 3}
+
+dit1 = dict.table(a = 1:2, b = 3:4)
+dit2 = dict.table(         b = 5:6, c = 8:9)
+update(d1, d2)
+#> {a = 1, b = 0, c = 3}
+update(d2, d1)
+#> {a = 1, b = 2, c = 3}
+
+l1 = list(1, b = 2)
+l2 = list(   b = 0, c = 3)
+update(l1, l2)
+#> [[1]]
+#> [1] 1
+#> 
+#> $b
+#> [1] 0
+#> 
+#> $c
+#> [1] 3
+#> 
+update(l2, l1)
+#> $b
+#> [1] 2
+#> 
+#> $c
+#> [1] 3
+#> 
+#> [[3]]
+#> [1] 1
+#> 
+
+
+
- - - + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 80b7cca2..0dbecf03 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -1,8 +1,38 @@ + + https://github.com/rpahl/container/404.html + + + https://github.com/rpahl/container/articles/code-development.html + + + https://github.com/rpahl/container/articles/container.html + + + https://github.com/rpahl/container/articles/deque-set-dict.html + + + https://github.com/rpahl/container/articles/index.html + + + https://github.com/rpahl/container/articles/manage-data-columns.html + + + https://github.com/rpahl/container/articles/parameter-list.html + + + https://github.com/rpahl/container/articles/reference-semantics.html + + + https://github.com/rpahl/container/authors.html + https://github.com/rpahl/container/index.html + + https://github.com/rpahl/container/news/index.html + https://github.com/rpahl/container/reference/add.html @@ -21,6 +51,12 @@ https://github.com/rpahl/container/reference/clone.html + + https://github.com/rpahl/container/reference/container-deprecated.html + + + https://github.com/rpahl/container/reference/container-pkg.html + https://github.com/rpahl/container/reference/Container.html @@ -46,7 +82,7 @@ https://github.com/rpahl/container/reference/Deque.html - https://github.com/rpahl/container/reference/DequeS3.html + https://github.com/rpahl/container/reference/dequeS3.html https://github.com/rpahl/container/reference/Dict.html @@ -55,7 +91,10 @@ https://github.com/rpahl/container/reference/dict.table.html - https://github.com/rpahl/container/reference/DictS3.html + https://github.com/rpahl/container/reference/dictS3.html + + + https://github.com/rpahl/container/reference/dicttable.html https://github.com/rpahl/container/reference/discard.html @@ -63,12 +102,21 @@ https://github.com/rpahl/container/reference/discard_at.html + + https://github.com/rpahl/container/reference/get_label.html + https://github.com/rpahl/container/reference/has.html https://github.com/rpahl/container/reference/has_name.html + + https://github.com/rpahl/container/reference/index.html + + + https://github.com/rpahl/container/reference/is.subsettable.html + https://github.com/rpahl/container/reference/is_empty.html @@ -102,6 +150,9 @@ https://github.com/rpahl/container/reference/peek.html + + https://github.com/rpahl/container/reference/peekleft.html + https://github.com/rpahl/container/reference/peek_at.html @@ -130,7 +181,7 @@ https://github.com/rpahl/container/reference/Set.html - https://github.com/rpahl/container/reference/SetS3.html + https://github.com/rpahl/container/reference/setS3.html https://github.com/rpahl/container/reference/unpack.html @@ -138,22 +189,4 @@ https://github.com/rpahl/container/reference/update.html - - https://github.com/rpahl/container/articles/code-development.html - - - https://github.com/rpahl/container/articles/container.html - - - https://github.com/rpahl/container/articles/deque-set-dict.html - - - https://github.com/rpahl/container/articles/manage-data-columns.html - - - https://github.com/rpahl/container/articles/parameter-list.html - - - https://github.com/rpahl/container/articles/reference-semantics.html - diff --git a/has.Rd b/has.Rd deleted file mode 100644 index f0eca093..00000000 --- a/has.Rd +++ /dev/null @@ -1,47 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/has.R -\name{has} -\alias{has} -\alias{has.Container} -\alias{has.dict.table} -\title{Check for Element} -\usage{ -has(x, ...) - -\method{has}{Container}(x, elem, ...) - -\method{has}{dict.table}(x, column, ...) -} -\arguments{ -\item{x}{any \code{R} object.} - -\item{...}{additional arguments to be passed to or from methods.} - -\item{elem}{some element to be found.} - -\item{column}{vector of values with the same length as the number of rows -of the \code{dict.table}.} -} -\value{ -\code{TRUE} if element is in \code{x} and otherwise \code{FALSE}. - -For \code{dict.table}, \code{TRUE} if column exists in \code{x} otherwise \code{FALSE}. -} -\description{ -Check for Element -} -\examples{ - -co = container(1, 2, mean) -has(co, 1) # TRUE -has(co, mean) # TRUE -has(co, 1:2) # FALSE - -dit = dict.table(a = 1:3, b = as.list(4:6)) -has(dit, 1:3) # TRUE -has(dit, 4:6) # FALSE -has(dit, as.list(4:6)) # TRUE -} -\seealso{ -\code{\link[=has_name]{has_name()}} -} diff --git a/has_name.Rd b/has_name.Rd deleted file mode 100644 index 18b7dccd..00000000 --- a/has_name.Rd +++ /dev/null @@ -1,42 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/has_name.R -\name{has_name} -\alias{has_name} -\alias{has_name.Container} -\alias{has_name.dict.table} -\title{Check for Name} -\usage{ -has_name(x, name) - -\method{has_name}{Container}(x, name) - -\method{has_name}{dict.table}(x, name) -} -\arguments{ -\item{x}{any \code{R} object.} - -\item{name}{\code{character} the name to be found.} -} -\value{ -\code{TRUE} if name is in \code{x} and otherwise \code{FALSE}. - -For \code{dict.table} \code{TRUE} if the dict.table objects has the given -column name, otherwise \code{FALSE}. -} -\description{ -Check for Name -} -\examples{ - -co = container(a = 1, 2, f = mean) -has_name(co, "a") # TRUE -has_name(co, "f") # TRUE -has_name(co, "2") # FALSE - -dit = dict.table(a = 1:2, b = 3:4) -has_name(dit, "a") # TRUE -has_name(dit, "x") # FALSE -} -\seealso{ -\code{\link[=has]{has()}} -} diff --git a/inst/tinytest/test_0-dict.table.R b/inst/tinytest/test_0-dict.table.R index 451050e9..040cc6b8 100644 --- a/inst/tinytest/test_0-dict.table.R +++ b/inst/tinytest/test_0-dict.table.R @@ -125,15 +125,12 @@ expect_error(delete_at(dit, 3), "index out of range \\(ncol = 2\\): 3") expect_true(identical(dit, dit.copy)) # dit.copy has not changed -# dict.table can be printed +# printed dict.table has the expected header dit = dict.table(A = 1:2, B = 2:1) -options(datatable.print.class=FALSE) out <- capture.output(print(dit)) -out.expected <- c(" with 2 rows and 2 columns", - " A B", - "1: 1 2", - "2: 2 1") -ee(out, out.expected) +header = out[1] +expected_header = " with 2 rows and 2 columns" +ee(header, expected_header) # dict.table has a size diff --git a/is_empty.Rd b/is_empty.Rd deleted file mode 100644 index a4112459..00000000 --- a/is_empty.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/is_empty.R -\name{is_empty} -\alias{is_empty} -\alias{is_empty.Container} -\alias{is_empty.dict.table} -\title{Check if Object is Empty} -\usage{ -is_empty(x) - -\method{is_empty}{Container}(x) - -\method{is_empty}{dict.table}(x) -} -\arguments{ -\item{x}{any \code{R} object.} -} -\value{ -\code{TRUE} if object is empty otherwise \code{FALSE}. -} -\description{ -Check if Object is Empty -} -\examples{ - -co = container(1, 2) -is_empty(co) -is_empty(clear(co)) - -d = dict.table(a = 1:4, b = 4:1) -is_empty(d) -is_empty(clear(d)) -} diff --git a/iterS3.Rd b/iterS3.Rd deleted file mode 100644 index 752c7765..00000000 --- a/iterS3.Rd +++ /dev/null @@ -1,103 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/0-IteratorS3.R -\name{iterS3} -\alias{iterS3} -\alias{iter} -\alias{iter.Container} -\alias{iter.default} -\alias{is.iterator} -\alias{is.iterable} -\alias{begin} -\alias{get_value} -\alias{get_next} -\alias{has_next} -\alias{has_value} -\alias{pos} -\alias{next_iter} -\alias{reset_iter} -\alias{length.Iterator} -\title{Iterate over Sequences} -\usage{ -iter(x, ...) - -\method{iter}{Container}(x, ...) - -\method{iter}{default}(x, ...) - -is.iterator(x) - -is.iterable(x) - -begin(it) - -get_value(it) - -get_next(it) - -has_next(it) - -has_value(it) - -pos(it) - -next_iter(it) - -reset_iter(it) - -\method{length}{Iterator}(x) -} -\arguments{ -\item{x}{an object of class \link{Iterable} or any other \code{R} object. In the -latter case, \code{x} will always be coerced to a base \code{R} \link{list} prior to creating -the \link{Iterator}.} - -\item{...}{other parameters passed to or from methods} - -\item{it}{\code{Iterator} object} -} -\value{ -\code{length} returns the number of elements that can be iterated over. -} -\description{ -An \code{Iterator} is an object that allows to iterate over -sequences. It implements \code{\link[=next_iter]{next_iter()}} and \code{\link[=get_value]{get_value()}} to iterate and retrieve the -value of the sequence it is associated with. -For documentation of the methods see \link{Iterator}. -} -\examples{ -# Numeric Vector -v = 1:3 -it = iter(v) -it - -try(it$get_value()) # iterator does not point at a value - -has_value(it) -has_next(it) -next_iter(it) -get_value(it) -get_next(it) -get_next(it) -it -has_next(it) -begin(it) -get_value(it) -reset_iter(it) - -# Works on copy of Container -co = container(1, 2, 3) -it = iter(co) -get_next(it) -ref_discard(co, 2) -co -it -get_next(it) -ref_clear(co) -co -it -get_next(it) -begin(it) -} -\seealso{ -For the class documentation see \link{Iterator}. -} diff --git a/peek.Rd b/peek.Rd deleted file mode 100644 index 051a8898..00000000 --- a/peek.Rd +++ /dev/null @@ -1,47 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/peek.R -\name{peek} -\alias{peek} -\alias{peekleft} -\alias{peek.Deque} -\alias{peekleft.Deque} -\title{Peek at Left or Right of a Deque} -\usage{ -peekleft(x, default = NULL) - -peek(x, default = NULL) - -\method{peek}{Deque}(x, default = NULL) - -\method{peekleft}{Deque}(x, default = NULL) -} -\arguments{ -\item{x}{a \code{Deque} object.} - -\item{default}{value to be returned if peeked value does not exist.} -} -\value{ -The first (\code{peekleft}) or last (\code{peek}) element. -} -\description{ -Try to access first or last element and return some default value if not found. -In contrast to \verb{[at2()]}, this function provides a less stricter element -access, that is, it remains valid even if peeked elements don't exist. -} -\details{ -\code{peek} peek at last element of a \code{Deque}. - -\code{peekleft} peek at first element of a \code{Deque}. -} -\examples{ -# Deque -d = deque(1, 2, 3) -peek(d) -peekleft(d) -peek(deque()) -peek(deque(), default = 0) -peekleft(deque(), default = 0) -} -\seealso{ -\code{\link[=at2]{at2()}} for strict element extraction -} diff --git a/peek_at.Rd b/peek_at.Rd deleted file mode 100644 index a156b289..00000000 --- a/peek_at.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/peek_at.R -\name{peek_at} -\alias{peek_at} -\alias{peek_at.Container} -\alias{peek_at.dict.table} -\title{Peek at Indices} -\usage{ -peek_at(.x, ...) - -\method{peek_at}{Container}(.x, ..., .default = NULL) - -\method{peek_at}{dict.table}(.x, ..., .default = NULL) -} -\arguments{ -\item{.x}{an \code{R} object of the respective class.} - -\item{...}{indices of elements to be extracted} - -\item{.default}{value to be returned if peeked value does not exist.} -} -\value{ -For \code{Container}, returns the value at the given indices or (if not -found) the given default value. - -For \code{dict.table}, returns the columns at the given indices or (if not -found) columns with the given default value. -} -\description{ -Try to access elements and return default values if not found. -In contrast to \verb{[at()]}, this function provides a less stricter element -access, that is, it remains valid even if elements don't exist. -} -\details{ -\code{peek_at} tries to access specific values. -} -\examples{ - -# Container -co = container(a = 1, 2, b = 3, 4) -peek_at(co, 1) -peek_at(co, "a") -peek_at(co, "x") -peek_at(co, "x", .default = 0) -peek_at(co, "a", "x", 2, 9, .default = -1) - -# Dict -d = dict(a = 1, b = 1:3) -peek_at(d, "b") -peek_at(d, "x") -peek_at(d, "x", .default = 4:7) - -# dict.table -dit = dict.table(a = 1:3, b = 4:6) -peek_at(dit, "a") -peek_at(dit, 1) -peek_at(dit, 3) -peek_at(dit, "x") -peek_at(dit, "x", .default = 0) -peek_at(dit, "a", "x", .default = 0) -} -\seealso{ -\code{\link[=at]{at()}} for strict element extraction -} diff --git a/peek_at2.Rd b/peek_at2.Rd deleted file mode 100644 index 8a4df0ef..00000000 --- a/peek_at2.Rd +++ /dev/null @@ -1,63 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/peek_at2.R -\name{peek_at2} -\alias{peek_at2} -\alias{peek_at2.Container} -\alias{peek_at2.dict.table} -\title{Peek at Single Index} -\usage{ -peek_at2(x, index, default = NULL) - -\method{peek_at2}{Container}(x, index, default = NULL) - -\method{peek_at2}{dict.table}(x, index, default = NULL) -} -\arguments{ -\item{x}{an \code{R} object of the respective class.} - -\item{index}{\code{character} name or \code{numeric} position of the sought value.} - -\item{default}{value to be returned if peeked value does not exist.} -} -\value{ -For \code{Container}, returns the value at the given index or (if not -found) the given default value. - -For \code{dict.table}, returns the column named \code{index} if it exist -otherwise the given \code{default} value. If the default length does not match -the number of rows, it is recycled accordingly and a warning is given, -unless the default value has a length of 1, in which case recycling is -done silently. -} -\description{ -Try to access element and return some default value if not found. -In contrast to \verb{[at2()]}, this function provides a less stricter element -access, that is, it remains valid even if peeked elements don't exist. -} -\examples{ - -# Container -co = container(a = 1, 2, b = 3, 4) -peek_at2(co, 1) -peek_at2(co, "a") -peek_at2(co, "x") -peek_at2(co, "x", default = 0) - -# Dict -d = dict(a = 1, b = 1:3) -peek_at2(d, "b") -peek_at2(d, "x") -peek_at2(d, "x", default = 4:7) - -# dict.table -dit = dict.table(a = 1:3, b = 4:6) -peek_at2(dit, "a") -peek_at2(dit, 1) -peek_at2(dit, 3) -peek_at2(dit, 3, default = 9) -peek_at2(dit, "x") -peek_at2(dit, "x", default = 0) -} -\seealso{ -\code{\link[=at2]{at2()}} for strict element extraction -} diff --git a/pop.Rd b/pop.Rd deleted file mode 100644 index 5dec15b8..00000000 --- a/pop.Rd +++ /dev/null @@ -1,82 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pop.R -\name{pop} -\alias{pop} -\alias{ref_pop} -\alias{ref_popleft} -\alias{ref_pop.Deque} -\alias{ref_popleft.Deque} -\alias{ref_pop.Container} -\alias{ref_pop.dict.table} -\title{Get and Remove Element} -\usage{ -ref_pop(.x, ...) - -ref_popleft(.x, ...) - -\method{ref_pop}{Deque}(.x, ...) - -\method{ref_popleft}{Deque}(.x, ...) - -\method{ref_pop}{Container}(.x, index, ...) - -\method{ref_pop}{dict.table}(.x, index, ...) -} -\arguments{ -\item{.x}{any \code{R} object.} - -\item{...}{additional arguments to be passed to or from methods.} - -\item{index}{\code{character} name or \code{numeric} position of value to be popped} -} -\value{ -For \code{Deque} the first (\code{ref_popleft}) or last (\code{ref_pop}) element of -the deque after it was removed. - -For \code{Container} the value at the given index after it was removed from -the \code{Container} object. If \code{index} is not found, an error is raised. - -For \code{dict.table}, returns the column at the given \code{index} after it was -removed from the \code{dict.table}. If column does not exist, an error is raised. -} -\description{ -Search and return an element and remove it afterwards from the object. -If the element is not found, signal an error. -} -\details{ -All functions work by reference, that is, the original object is altered. -\code{ref_pop(.x)} tries to access specific values. - -\code{ref_popleft(.x)} pops first element of a \code{Deque}. -} -\examples{ -# Deque -d = deque(1, 2, 3) -ref_pop(d) -ref_popleft(d) - -try({ -ref_pop(deque()) # pop at empty Deque -}) - -# Container -co = container(a = 1, b = 1:3, d = "foo") -ref_pop(co, "b") -ref_pop(co, 1) - -try({ -ref_pop(co, "x") # index 'x' not found -}) - -# dict.table -dit = dict.table(a = 1:3, b = 4:6) -ref_pop(dit, "a") -ref_pop(dit, 1) - -try({ -ref_pop(dit, "x") # index 'x' not found -}) -} -\seealso{ -\code{\link[=peek]{peek()}} -} diff --git a/rename.Rd b/rename.Rd deleted file mode 100644 index 712e2e68..00000000 --- a/rename.Rd +++ /dev/null @@ -1,68 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rename.R -\name{rename} -\alias{rename} -\alias{ref_rename} -\alias{rename.Container} -\alias{rename.dict.table} -\alias{ref_rename.dict.table} -\alias{rename.default} -\title{Rename Elements Safely} -\usage{ -rename(.x, old, new) - -ref_rename(.x, old, new) - -\method{rename}{Container}(.x, old, new) - -\method{rename}{dict.table}(.x, old, new) - -\method{ref_rename}{dict.table}(.x, old, new) - -\method{rename}{default}(.x, old, new) -} -\arguments{ -\item{.x}{\code{dict.table} object} - -\item{old}{\code{character} old name} - -\item{new}{\code{character} new name} -} -\value{ -For standard \code{R} vectors renames \code{old} to \code{new} and returns the -renamed vector. - -For \code{Container}, an object of class \code{Container} (or one of the -respective derived classes). - -For \code{dict.table} renames key \code{old} to \code{new} in place (i.e. by -reference) and invisibly returns the \code{\link[=dict.table]{dict.table()}} object. -} -\description{ -Search for old name and replace it by new name. If either the -old name does not exist or the name would result in a name-clash with an -already existing name, an error is signaled. -} -\details{ -The passed old and new names can be vectors but always must have -the same length and must be unique to prevent double-renaming. - -\code{rename} uses copy semantics while \code{ref_rename} works by reference, -that is, it renames elements in place. -} -\examples{ - -# Container -co = container(a = 1, b = 2, 3) -rename(co, c("a", "b"), c("a1", "y")) -print(co) -ref_rename(co, c("a", "b"), c("a1", "y")) -print(co) - -# dict.table -dit = dict.table(a = 1, b = 2, c = 3) -rename(dit, c("a", "b"), c("a1", "y")) -print(dit) -ref_rename(dit, c("a", "b"), c("a1", "y")) -print(dit) -} diff --git a/replace.Rd b/replace.Rd deleted file mode 100644 index 38554b30..00000000 --- a/replace.Rd +++ /dev/null @@ -1,69 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/replace.R -\name{replace} -\alias{replace} -\alias{ref_replace} -\alias{replace.Container} -\alias{ref_replace.Container} -\alias{replace.Dict} -\alias{ref_replace.Dict} -\title{Replace Values in Containers Safely} -\usage{ -replace(.x, ...) - -ref_replace(.x, ...) - -\method{replace}{Container}(.x, old, new, add = FALSE, ...) - -\method{ref_replace}{Container}(.x, old, new, add = FALSE, ...) - -\method{replace}{Dict}(.x, old, new, ...) - -\method{ref_replace}{Dict}(.x, old, new, ...) -} -\arguments{ -\item{.x}{any \code{R} object.} - -\item{...}{additional arguments to be passed to or from methods.} - -\item{old}{old element to be found and replaced.} - -\item{new}{the new element replacing the old one.} - -\item{add}{\code{logical} if \code{FALSE} (default) and element was not found, -an error is given. In contrast, if set to \code{TRUE} the new element is added -regardless of whether it is used as a replacement for an existing element or -just added as a new element.} -} -\value{ -For \code{Container}, an object of class \code{Container} (or one of the -respective derived classes). - -For \code{Dict} an object of class \code{Dict}. -} -\description{ -Try to find and replace elements and signal an error if not -found, unless it is stated to explicitly add the element (see option \code{add}). -} -\details{ -\code{replace} uses copy semantics while \code{ref_replace} works by reference. -} -\examples{ - -co = container("x", 9) -replace(co, 9, 0) -replace(co, "x", 0) -try({ -replace(co, "z", 0) # old element ("z") is not in Container -}) -replace(co, "z", 0, add = TRUE) # just add the zero without replacement - - -d = dict(a = 1, b = "z") -replace(d, 1, 1:5) -replace(d, "z", "a") - -try({ -replace(d, "a", 2) # old element ("a") is not in Dict -}) -} diff --git a/replace_at.Rd b/replace_at.Rd deleted file mode 100644 index dc8804ff..00000000 --- a/replace_at.Rd +++ /dev/null @@ -1,75 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/replace_at.R -\name{replace_at} -\alias{replace_at} -\alias{ref_replace_at} -\alias{replace_at.Container} -\alias{ref_replace_at.Container} -\alias{replace_at.dict.table} -\alias{ref_replace_at.dict.table} -\title{Replace Values at Indices Safely} -\usage{ -replace_at(.x, ...) - -ref_replace_at(.x, ...) - -\method{replace_at}{Container}(.x, ..., .add = FALSE) - -\method{ref_replace_at}{Container}(.x, ..., .add = FALSE) - -\method{replace_at}{dict.table}(.x, ..., .add = FALSE) - -\method{ref_replace_at}{dict.table}(.x, ..., .add = FALSE) -} -\arguments{ -\item{.x}{any \code{R} object.} - -\item{...}{either name = value pairs or two vectors/lists with names/values -to be replaced.} - -\item{.add}{\code{logical} if \code{FALSE} (default) and index is invalid, an error is -given. If set to \code{TRUE} the new element is added at the given index -regardless whether the index existed or not. Indices can consist of numbers -or names or both, except when adding values at new indices, which is only -allowed for names.} -} -\value{ -For \code{Container}, an object of class \code{Container} (or one of the -respective derived classes). - -For \code{dict.table} an object of class \code{dict.table}. -} -\description{ -Try to find and replace elements at given indices and signal an -error if not found, unless it is stated to explicitly add the element (see -option \code{add}). -} -\details{ -\code{replace_at} uses copy semantics while \code{ref_replace_at} works by -reference. -} -\examples{ - -co = container(a = 0, b = "z") -replace_at(co, a = 1, b = 2) -replace_at(co, 1:2, 1:2) # same -replace_at(co, c("a", "b"), list(1, 2)) # same - -try({ -replace_at(co, x = 1) # names(s) not found: 'x' -}) -replace_at(co, x = 1, .add = TRUE) # ok (adds x = 1) - - -dit = dict.table(a = 1:3, b = 4:6) -replace_at(dit, a = 3:1) -replace_at(dit, 1, 3:1) # same -replace_at(dit, "a", 3:1) # same -replace_at(dit, a = 3:1, b = 6:4) -replace_at(dit, 1:2, list(3:1, 6:4)) # same - -try({ -replace_at(dit, x = 1) # column(s) not found: 'x' -}) -replace_at(dit, x = 1, .add = TRUE) # ok (adds column) -} diff --git a/rev.Rd b/rev.Rd deleted file mode 100644 index 70066088..00000000 --- a/rev.Rd +++ /dev/null @@ -1,40 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rev.R -\name{rev} -\alias{rev} -\alias{ref_rev} -\alias{ref_rev.Deque} -\alias{rev.Deque} -\title{Reverse Elements} -\usage{ -ref_rev(x) - -\method{ref_rev}{Deque}(x) - -\method{rev}{Deque}(x) -} -\arguments{ -\item{x}{\code{Deque} object} -} -\value{ -For \code{Deque}, an object of class \code{Deque} -} -\description{ -\code{rev} provides a reversed version of its argument. -} -\details{ -\code{rev} uses copy semantics while \code{ref_rev} works by reference, -that is, it reverse all elements in place. -} -\examples{ - -d = deque(a = 1, b = 2, 3) -rev(d) -print(d) -ref_rev(d) -print(d) - -} -\seealso{ -\code{\link[base:rev]{base::rev()}} -} diff --git a/rotate.Rd b/rotate.Rd deleted file mode 100644 index e5226757..00000000 --- a/rotate.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rotate.R -\name{rotate} -\alias{rotate} -\alias{ref_rotate} -\alias{rotate.Deque} -\alias{ref_rotate.Deque} -\title{Rotate Elements} -\usage{ -rotate(x, n = 1L) - -ref_rotate(x, n = 1L) - -\method{rotate}{Deque}(x, n = 1L) - -\method{ref_rotate}{Deque}(x, n = 1L) -} -\arguments{ -\item{x}{any \code{R} object.} - -\item{n}{\code{integer} number of steps to rotate} -} -\value{ -For \code{Deque} returns the rotated \code{\link[=Deque]{Deque()}} object. -} -\description{ -Rotate all elements \code{n} steps to the right. If n is -negative, rotate to the left. -} -\details{ -While \code{rotate} uses copy semantics, \code{ref_rotate} works by reference, -that is, rotates in place on the original object. -} -\examples{ -d = deque(1, 2, 3, 4) -rotate(d) -rotate(d, n = 2) -} diff --git a/unpack.Rd b/unpack.Rd deleted file mode 100644 index 180dede1..00000000 --- a/unpack.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/unpack.R -\name{unpack} -\alias{unpack} -\title{Unpack Nested Objects} -\usage{ -unpack(x, recursive = TRUE, use.names = TRUE) -} -\arguments{ -\item{x}{any \code{R} object} - -\item{recursive}{\code{logical} descend recursively into nested objects?} - -\item{use.names}{\code{logical} Should names be preserved?} -} -\value{ -a \code{list} -} -\description{ -Similary to \code{\link[=unlist]{unlist()}} recursively unpacks any (possibly nested) structure -into a flat list. In contrast to \code{\link[=unlist]{unlist()}}, \code{\link[=unpack]{unpack()}} also works with -(possibly nested) \code{\link[=Container]{Container()}} objects. In principle, it works for any -object that can be transformed to a list via \code{as.list}. -} diff --git a/update.Rd b/update.Rd deleted file mode 100644 index cad0c257..00000000 --- a/update.Rd +++ /dev/null @@ -1,65 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/update.R -\name{update} -\alias{update} -\alias{ref_update} -\alias{update.Container} -\alias{ref_update.Container} -\alias{update.dict.table} -\alias{ref_update.dict.table} -\alias{update.list} -\title{Update Object with Elements from Another Object} -\usage{ -ref_update(object, other, ...) - -\method{update}{Container}(object, other, ...) - -\method{ref_update}{Container}(object, other, ...) - -\method{update}{dict.table}(object, other, ...) - -\method{ref_update}{dict.table}(object, other, ...) - -\method{update}{list}(object, other, ...) -} -\arguments{ -\item{object}{any \code{R} object} - -\item{other}{any object of the same type as \code{object}} - -\item{...}{additional arguments to be passed to or from methods.} -} -\value{ -For \code{Container}, an object of class \code{Container} (or one of the -respective derived classes). - -For \code{dict.table} an object of class \code{dict.table}. - -For \code{list}, an updated object of class \code{list}. -} -\description{ -Takes an object and updates it with values from another object -by replacing the values at existing names and adding values at new names of -the other object. A common use case is to update parameter lists. -} -\details{ -\code{update} uses copy semantics while \code{ref_update} works by reference, -that is, updates in place. -} -\examples{ - -d1 = dict(a = 1, b = 2) -d2 = dict( b = 0, c = 3) -update(d1, d2) # {a = 1, b = 0, c = 3} -update(d2, d1) # {a = 1, b = 2, c = 3} - -dit1 = dict.table(a = 1:2, b = 3:4) -dit2 = dict.table( b = 5:6, c = 8:9) -update(d1, d2) -update(d2, d1) - -l1 = list(1, b = 2) -l2 = list( b = 0, c = 3) -update(l1, l2) -update(l2, l1) -} diff --git a/vignettes/manage-data-columns_cache/html/__packages b/vignettes/manage-data-columns_cache/html/__packages index 7a6e76c1..372fbd2c 100644 --- a/vignettes/manage-data-columns_cache/html/__packages +++ b/vignettes/manage-data-columns_cache/html/__packages @@ -1,4 +1,3 @@ -base container dplyr microbenchmark diff --git a/vignettes/manage-data-columns_cache/html/benchmark1_88fc4c4247df168c927bdee10517e067.RData b/vignettes/manage-data-columns_cache/html/benchmark1_88fc4c4247df168c927bdee10517e067.RData deleted file mode 100644 index d032216e..00000000 Binary files a/vignettes/manage-data-columns_cache/html/benchmark1_88fc4c4247df168c927bdee10517e067.RData and /dev/null differ diff --git a/vignettes/manage-data-columns_cache/html/benchmark1_88fc4c4247df168c927bdee10517e067.rdb b/vignettes/manage-data-columns_cache/html/benchmark1_88fc4c4247df168c927bdee10517e067.rdb deleted file mode 100644 index 93f337b2..00000000 Binary files a/vignettes/manage-data-columns_cache/html/benchmark1_88fc4c4247df168c927bdee10517e067.rdb and /dev/null differ diff --git a/vignettes/manage-data-columns_cache/html/benchmark1_88fc4c4247df168c927bdee10517e067.rdx b/vignettes/manage-data-columns_cache/html/benchmark1_88fc4c4247df168c927bdee10517e067.rdx deleted file mode 100644 index 149e6602..00000000 Binary files a/vignettes/manage-data-columns_cache/html/benchmark1_88fc4c4247df168c927bdee10517e067.rdx and /dev/null differ diff --git a/vignettes/manage-data-columns_cache/html/benchmark2_5b0b0cd67af48dad98d48d0f30cb0700.RData b/vignettes/manage-data-columns_cache/html/benchmark2_5b0b0cd67af48dad98d48d0f30cb0700.RData deleted file mode 100644 index 7d607af6..00000000 Binary files a/vignettes/manage-data-columns_cache/html/benchmark2_5b0b0cd67af48dad98d48d0f30cb0700.RData and /dev/null differ diff --git a/vignettes/manage-data-columns_cache/html/benchmark2_5b0b0cd67af48dad98d48d0f30cb0700.rdb b/vignettes/manage-data-columns_cache/html/benchmark2_5b0b0cd67af48dad98d48d0f30cb0700.rdb deleted file mode 100644 index 069cc3fb..00000000 Binary files a/vignettes/manage-data-columns_cache/html/benchmark2_5b0b0cd67af48dad98d48d0f30cb0700.rdb and /dev/null differ diff --git a/vignettes/manage-data-columns_cache/html/benchmark2_5b0b0cd67af48dad98d48d0f30cb0700.rdx b/vignettes/manage-data-columns_cache/html/benchmark2_5b0b0cd67af48dad98d48d0f30cb0700.rdx deleted file mode 100644 index 4501c762..00000000 Binary files a/vignettes/manage-data-columns_cache/html/benchmark2_5b0b0cd67af48dad98d48d0f30cb0700.rdx and /dev/null differ diff --git a/vignettes/manage-data-columns_cache/html/benchmark3_f221dbcfd9a86d7873ddf3bad7cc46e6.RData b/vignettes/manage-data-columns_cache/html/benchmark3_f221dbcfd9a86d7873ddf3bad7cc46e6.RData deleted file mode 100644 index 6dea1d3a..00000000 Binary files a/vignettes/manage-data-columns_cache/html/benchmark3_f221dbcfd9a86d7873ddf3bad7cc46e6.RData and /dev/null differ diff --git a/vignettes/manage-data-columns_cache/html/benchmark3_f221dbcfd9a86d7873ddf3bad7cc46e6.rdb b/vignettes/manage-data-columns_cache/html/benchmark3_f221dbcfd9a86d7873ddf3bad7cc46e6.rdb deleted file mode 100644 index 01059a34..00000000 Binary files a/vignettes/manage-data-columns_cache/html/benchmark3_f221dbcfd9a86d7873ddf3bad7cc46e6.rdb and /dev/null differ diff --git a/vignettes/manage-data-columns_cache/html/benchmark3_f221dbcfd9a86d7873ddf3bad7cc46e6.rdx b/vignettes/manage-data-columns_cache/html/benchmark3_f221dbcfd9a86d7873ddf3bad7cc46e6.rdx deleted file mode 100644 index ef3670e6..00000000 Binary files a/vignettes/manage-data-columns_cache/html/benchmark3_f221dbcfd9a86d7873ddf3bad7cc46e6.rdx and /dev/null differ