stan-dev / stan-dev/posterior

[FR?] rvar works in data.frame but not data.table

Open
#234 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
R
Stars
171
Forks
26
Avg merge
2d 18h
Merged PRs (30d)
3

Description

Not sure if this is a posterior issue or data.table issue but it looks like you cannot put rvars into data.table but it does work with data.frame

library(data.table)
library(posterior)
n <- 4   # length of output vector
x_rvar <- rvar(array(rnorm(4000*n, mean = 1, sd = 1), dim = c(4000, n)))
x_rvar
# rvar<4000>[4] mean ± sd:
#   [1] 0.98 ± 1.00  1.00 ± 1.02  1.00 ± 0.99  0.99 ± 0.99 
# does not work :(
ex_dt = data.table(ex = x_rvar)
ex_dt
# Empty data.table (0 rows and 1 cols): ex
# does work
ex_df = data.frame(ex = x_rvar)
ex_df
# ex
# 1 0.9778591 ± 1.0010389
# 2 1.0015836 ± 1.0206705
# 3 0.9964342 ± 0.9948071
# 4 0.9947569 ± 0.9921549

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the reported R example with posterior::rvar, data.table, and data.frame to reproduce the empty data.table result. Compare how rvar is handled by data.table versus data.frame, then determine whether the relevant change belongs in posterior or data.table; done means the example produces the expected four-row data.table without regressing data.frame behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.