Skip to content

wonky error messages in calculate #784

@goldingn

Description

@goldingn

The error messages are wonky for calculate(), in the event a user provides a greta array with unknown values:

library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#> 
#>     %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#>     eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#>     tapply

# Error message mentions lapply?
# It says we need to provide values for a, but not that we could also set `nsim`
a <- normal(0, 1)
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#> 
calculate(a)
#> Error in `lapply()` at greta/R/calculate.R:407:5:
#> ! Please provide values for the following 1 <greta_array>:
#> `a`
#> Backtrace:
#>      ▆
#>   1. └─greta::calculate(a)
#>   2.   ├─base::with(...) at greta/R/calculate.R:162:3
#>   3.   ├─reticulate:::with.python.builtin.object(...)
#>   4.   │ ├─base::tryCatch(...)
#>   5.   │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>   6.   │ └─base::force(expr)
#>   7.   └─greta:::calculate_list(...) at greta/R/calculate.R:247:7
#>   8.     └─base::lapply(...) at greta/R/calculate.R:407:5
#>   9.       └─greta (local) FUN(X[[i]], ...)
#>  10.         └─rlang::abort(message = msg, call = call) at greta/R/checkers.R:732:5

# Error message mentions lapply?
# It says it can't find the name of an object, but not why it is looking for one.
# It also doesn't say that we could also set `nsim`
b <- 1 + normal(0, 1)
calculate(b)
#> Error in `lapply()` at greta/R/calculate.R:407:5:
#> ! The names of the missing <greta_array>s could not be detected
#> Backtrace:
#>      ▆
#>   1. └─greta::calculate(b)
#>   2.   ├─base::with(...) at greta/R/calculate.R:162:3
#>   3.   ├─reticulate:::with.python.builtin.object(...)
#>   4.   │ ├─base::tryCatch(...)
#>   5.   │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>   6.   │ └─base::force(expr)
#>   7.   └─greta:::calculate_list(...) at greta/R/calculate.R:247:7
#>   8.     └─base::lapply(...) at greta/R/calculate.R:407:5
#>   9.       └─greta (local) FUN(X[[i]], ...)
#>  10.         └─rlang::abort(message = msg, call = call) at greta/R/checkers.R:732:5

Created on 2025-03-27 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Monthly todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions