An open API service indexing awesome lists of open source software.

https://github.com/poissonconsulting/nlist

An R package to create and check numeric list objects
https://github.com/poissonconsulting/nlist

cran data-frame natomic nlist nlists r rstats

Last synced: 9 months ago
JSON representation

An R package to create and check numeric list objects

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# nlist nlist logo

[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R-CMD-check](https://github.com/poissonconsulting/nlist/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/nlist/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/nlist/graph/badge.svg)](https://app.codecov.io/gh/poissonconsulting/nlist)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit)
[![CRAN status](https://www.r-pkg.org/badges/version/nlist)](https://cran.r-project.org/package=nlist)
![CRAN downloads](https://cranlogs.r-pkg.org/badges/nlist)

`nlist` is an R package to create and manipulate numeric list (`nlist`) objects.

An `nlist` is an S3 class list of uniquely named numeric objects.
An numeric object is an integer or double vector, matrix or array.
`nlist` objects are the raw data inputs for analytic engines such as JAGS, STAN and TMB.

An `nlists` object is a S3 class list of `nlist` objects with the same names, dimensionalities and typeofs.
`nlists` objects are useful for storing multiple realizations of simulated data sets.
They can be converted to `coda::mcmc` and `coda::mcmc.list` objects.

## Demonstration

### `numeric`

An numeric object is an integer or double vector, matrix or array.

```{r}
library(nlist)
is.numeric(1L)
is.numeric(matrix(1:3))
```

### `nlist`

An `nlist` is an S3 class list of uniquely named numeric objects.

It is straightforward to create an new `nlist` object.
```{r}
library(nlist)

nlist <- nlist(x = 1, y = matrix(1:9, 3))
nlist
```

### `nlists`

An `nlists` object is a S3 class list of `nlist` objects with the same names, dimensionalities and typeofs.

The nchains attribute is used to keep track of the number of chains.

```{r}
nlists <- nlists(
nlist(x = 1, y = matrix(1:9, 3)),
nlist(x = -2, y = matrix(2:10, 3)),
nlist(x = 10, y = matrix(22:30, 3)),
nlist(x = -100, y = matrix(-2:-10, 3))
)

print(nlists)
```

### Coercion

#### nlist

A data.frame can be coerced to an `nlist` object
```{r}
data <- data.frame(
lgl = c(TRUE, NA),
dte = as.Date(c("2001-01-02", "2001-01-01")),
fac = factor(c("b", "a"))
)

as_nlist(data)
```

And an `nlist` objects can be converted to an `mcmc` or `term_frame` objects (and converted back again)
```{r}
as_mcmc(nlist)
as_term_frame(nlist)
```

#### nlists

The `estimates()` function can be used to aggregate an `nlists` object to an `nlist` object.
```{r}
estimates(nlists, fun = mean)
```

while the `tidy()` function treats the values as if they are MCMC samples
and summarises the terms as a tidy tibble.
```{r}
tidy(nlists, simplify = TRUE)
```

An `nlists` object can be converted to an `mcmc.list` object and a `term_frame`.
```{r}
as_mcmc_list(nlists)
as_term_frame(nlists)
```

An `nlists` object can have its chains split or collapsed.
```{r}
split_chains(nlists)
```

## Installation

### Release

To install the release version from [CRAN](https://CRAN.R-project.org/package=nlist).
```r
install.packages("nlist")
```

The website for the release version is at .

### Development

To install the development version from [GitHub](https://github.com/poissonconsulting/nlist)
```r
# install.packages("remotes")
remotes::install_github("poissonconsulting/nlist")
```

or from [r-universe](https://poissonconsulting.r-universe.dev/nlist).
```r
install.packages("nlist", repos = c("https://poissonconsulting.r-universe.dev", "https://cloud.r-project.org"))
```
## Contribution

Please report any [issues](https://github.com/poissonconsulting/nlist/issues).

[Pull requests](https://github.com/poissonconsulting/nlist/pulls) are always welcome.

## Code of Conduct

Please note that the nlist project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.