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
- Host: GitHub
- URL: https://github.com/poissonconsulting/nlist
- Owner: poissonconsulting
- License: other
- Created: 2019-06-27T15:51:53.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2023-05-28T22:57:45.000Z (about 3 years ago)
- Last Synced: 2024-06-11T17:11:51.506Z (about 2 years ago)
- Topics: cran, data-frame, natomic, nlist, nlists, r, rstats
- Language: R
- Homepage: https://poissonconsulting.github.io/nlist/
- Size: 1.23 MB
- Stars: 6
- Watchers: 5
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.Rmd
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
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 
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://github.com/poissonconsulting/nlist/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/poissonconsulting/nlist)
[](https://opensource.org/license/mit)
[](https://cran.r-project.org/package=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.