Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data frame printing and overwriting methods for greta arrays #625

Open
njtierney opened this issue Apr 30, 2024 · 1 comment
Open

data frame printing and overwriting methods for greta arrays #625

njtierney opened this issue Apr 30, 2024 · 1 comment
Labels
low hanging fruit Issue is simple to implement. Up Next
Milestone

Comments

@njtierney
Copy link
Collaborator

A few things:

  • When you put a greta array inside a tibble, it has a funky print method
  • a greta array inside a tibble can be pulled out and is still a greta array
  • a greta array in a data.frame prints NA
  • a greta array inside data.frame gets its class stripped off of it
library(tibble)
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
ihr_car_ratio <- greta::uniform(0,1)
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#> 

ihr_car_ratio
#> greta array (variable following a uniform distribution)
#> 
#>      [,1]
#> [1,]  ?

greta_tbl <- tibble(
    x = 1:5,
    car_ratio = ihr_car_ratio
)

greta_df <- data.frame(
    x = 1:5,
    car_ratio = ihr_car_ratio
)

greta_tbl
#> # A tibble: 5 × 2
#>       x car_ratio[,1] 
#>   <int> <gret_rry[,1]>
#> 1     1 NA            
#> 2     2 car_ratio[,1] 
#> 3     3 <gret_rry[,1]>
#> 4     4 NA            
#> 5     5 car_ratio[,1]
greta_df
#>   x car_ratio
#> 1 1        NA
#> 2 2        NA
#> 3 3        NA
#> 4 4        NA
#> 5 5        NA

greta_tbl$car_ratio
#> greta array (variable following a uniform distribution)
#> 
#>      [,1]
#> [1,]  ?
greta_df$car_ratio
#> [1] NA NA NA NA NA

Created on 2024-04-30 with reprex v2.1.0

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.3 (2024-02-29)
#>  os       macOS Sonoma 14.3.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Australia/Hobart
#>  date     2024-04-30
#>  pandoc   3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  base64enc     0.1-3      2015-07-28 [1] CRAN (R 4.3.0)
#>  callr         3.7.6      2024-03-25 [1] CRAN (R 4.3.1)
#>  cli           3.6.2      2023-12-11 [1] CRAN (R 4.3.1)
#>  coda          0.19-4.1   2024-01-31 [2] CRAN (R 4.3.1)
#>  codetools     0.2-20     2024-03-31 [2] CRAN (R 4.3.1)
#>  crayon        1.5.2      2022-09-29 [1] CRAN (R 4.3.0)
#>  digest        0.6.35     2024-03-11 [1] CRAN (R 4.3.1)
#>  evaluate      0.23       2023-11-01 [1] CRAN (R 4.3.1)
#>  fansi         1.0.6      2023-12-08 [1] CRAN (R 4.3.1)
#>  fastmap       1.1.1      2023-02-24 [1] CRAN (R 4.3.0)
#>  fs            1.6.3      2023-07-20 [1] CRAN (R 4.3.0)
#>  future        1.33.2     2024-03-26 [1] CRAN (R 4.3.1)
#>  globals       0.16.3     2024-03-08 [1] CRAN (R 4.3.1)
#>  glue          1.7.0      2024-01-09 [1] CRAN (R 4.3.1)
#>  greta       * 0.4.4.9000 2024-04-30 [1] local
#>  hms           1.1.3      2023-03-21 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.8.1    2024-04-04 [1] CRAN (R 4.3.1)
#>  jsonlite      1.8.8      2023-12-04 [1] CRAN (R 4.3.1)
#>  knitr         1.45       2023-10-30 [1] CRAN (R 4.3.1)
#>  lattice       0.22-6     2024-03-20 [1] CRAN (R 4.3.1)
#>  lifecycle     1.0.4      2023-11-07 [1] CRAN (R 4.3.1)
#>  listenv       0.9.1      2024-01-29 [2] CRAN (R 4.3.1)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.3.0)
#>  Matrix        1.6-5      2024-01-11 [1] CRAN (R 4.3.1)
#>  parallelly    1.37.1     2024-02-29 [1] CRAN (R 4.3.1)
#>  pillar        1.9.0      2023-03-22 [1] CRAN (R 4.3.0)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.3.0)
#>  png           0.1-8      2022-11-29 [1] CRAN (R 4.3.0)
#>  prettyunits   1.2.0      2023-09-24 [1] CRAN (R 4.3.1)
#>  processx      3.8.4      2024-03-16 [1] CRAN (R 4.3.1)
#>  progress      1.2.3      2023-12-06 [1] CRAN (R 4.3.1)
#>  ps            1.7.6      2024-01-18 [1] CRAN (R 4.3.1)
#>  purrr         1.0.2      2023-08-10 [1] CRAN (R 4.3.0)
#>  R.cache       0.16.0     2022-07-21 [2] CRAN (R 4.3.0)
#>  R.methodsS3   1.8.2      2022-06-13 [2] CRAN (R 4.3.0)
#>  R.oo          1.26.0     2024-01-24 [2] CRAN (R 4.3.1)
#>  R.utils       2.12.3     2023-11-18 [2] CRAN (R 4.3.1)
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.3.0)
#>  Rcpp          1.0.12     2024-01-09 [1] CRAN (R 4.3.1)
#>  reprex        2.1.0      2024-01-11 [2] CRAN (R 4.3.1)
#>  reticulate    1.36.0     2024-04-15 [2] CRAN (R 4.3.1)
#>  rlang         1.1.3      2024-01-10 [1] CRAN (R 4.3.1)
#>  rmarkdown     2.26       2024-03-05 [1] CRAN (R 4.3.1)
#>  rstudioapi    0.16.0     2024-03-24 [1] CRAN (R 4.3.1)
#>  sessioninfo   1.2.2      2021-12-06 [2] CRAN (R 4.3.0)
#>  styler        1.10.3     2024-04-07 [2] CRAN (R 4.3.1)
#>  tensorflow    2.16.0     2024-04-15 [2] CRAN (R 4.3.1)
#>  tfruns        1.5.2      2024-01-26 [2] CRAN (R 4.3.1)
#>  tibble      * 3.2.1      2023-03-20 [1] CRAN (R 4.3.0)
#>  utf8          1.2.4      2023-10-22 [1] CRAN (R 4.3.1)
#>  vctrs         0.6.5      2023-12-01 [1] CRAN (R 4.3.1)
#>  whisker       0.4.1      2022-12-05 [1] CRAN (R 4.3.0)
#>  withr         3.0.0      2024-01-16 [1] CRAN (R 4.3.1)
#>  xfun          0.43       2024-03-25 [1] CRAN (R 4.3.1)
#>  yaml          2.3.8      2023-12-11 [1] CRAN (R 4.3.1)
#> 
#>  [1] /Users/nick/Library/R/arm64/4.3/library
#>  [2] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
#> 
#> ─ Python configuration ───────────────────────────────────────────────────────
#>  python:         /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/bin/python
#>  libpython:      /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/libpython3.9.dylib
#>  pythonhome:     /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2:/Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2
#>  version:        3.9.18 | packaged by conda-forge | (main, Dec 23 2023, 16:35:41)  [Clang 16.0.6 ]
#>  numpy:          /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/python3.9/site-packages/numpy
#>  numpy_version:  1.26.4
#>  tensorflow:     /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/python3.9/site-packages/tensorflow
#>  
#>  NOTE: Python version was forced by use_python() function
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@njtierney
Copy link
Collaborator Author

This issue will require, I think, rewriting the greta array classes with a vctr class, https://vctrs.r-lib.org/articles/s3-vector.html, which overall I think might simplify some things, but will actually be a reasonably complex fix.

See an example of using vctrs with rray here: https://github.com/r-lib/rray/blob/main/R/rray.R#L67-L81

@njtierney njtierney moved this from Weekly Todo to Next Release in {greta} CRAN 0.5.1 release Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low hanging fruit Issue is simple to implement. Up Next
Projects
Status: Next Release
Development

No branches or pull requests

1 participant