r-lib / lobstr

Understanding complex R objects with tools similar to str()
https://lobstr.r-lib.org/
Other
303 stars 27 forks source link

Bad binding access #48

Open mjsteinbaugh opened 4 years ago

mjsteinbaugh commented 4 years ago

I'm seeing this error pop up inside of RStudio when attempting to call lobstr::obj_size(). I'm working on attempting to make a reprex. Just wanted to see if this is a known issue that anyone else has come across:

Error in obj_size_(dots, env, size_node(), size_vector()) : 
  bad binding access
Calls: obj_size -> obj_size_
Backtrace:
    █
 1. └─lobstr::obj_size(object)
 2.   └─lobstr:::obj_size_(dots, env, size_node(), size_vector())
mjsteinbaugh commented 4 years ago

I can also reproduce this error with the legacy pryr::object_size(), whereas utils::object.size() works as expected.

hadley commented 3 years ago

Can you provide a reprex?

PinkAppleFlower commented 3 years ago

I receive this error when attempting to calculate the size of tibble that is a link to Spark data table. Error shows up in both pryr and lobstr with slightly different semantics.

pryr: "<simpleError in object_sizes(list(...), env): bad binding access>"

lobstr: "<simpleError in objsize(dots, env, size_node(), size_vector()): bad binding access>"

The pryr information is not meant to be distracting/off topic, but rather hopefully add additional information that is helpful.

Also, I used the tidyft package to calculate object size and that worked.

LMK if you need a reprex or more info.

Thanks.

hadley commented 3 years ago

A reprex would be very useful because I'll need to figure out what's going wrong in the C code.

PinkAppleFlower commented 3 years ago

object size reprex zipped.zip

Above is the link to the notebook and the RMD file.

👍

Just let me know if you need anything else.

hadley commented 3 years ago

Could you please made a small reprex and include it inline?

PinkAppleFlower commented 3 years ago

Sure, here is just the code for the lobstr package. I hope this is minimal enough.

Convert the time series data to a tibble

EU_stock_tibl <- ts_tbl(EuStockMarkets)

Spark Connection

spark_connection <- spark_connect(master = "local")

Copy data to Spark

EU_stock_spark_link <- copy_to(spark_connection, EU_stock_tibl, "EU_stock_spark", overwrite = TRUE)

Size

tryCatch({ lobstr::obj_size(EU_stock_spark_link) }, error = print )

PinkAppleFlower commented 3 years ago

Just following up on this to see where things are at and if my code sample worked out as needed. I see it still has the reprex label. Datacamp uses the pypr package, but not the lobstr package in their course. I mentioned this issue to them so I am just following up as the ticket is still in my inbox.

hadley commented 3 years ago

Could you please rework your reproducible example to use the reprex package ? That makes it easier to see both the input and the output, formatted in such a way that I can easily re-run in a local session.

PinkAppleFlower commented 3 years ago

Yep, below is the example created with the reprex package. Thanks for letting me know this is what you were looking for.

library(pryr)
#> Registered S3 method overwritten by 'pryr':
#>   method      from
#>   print.bytes Rcpp
library(lobstr)
#> 
#> Attaching package: 'lobstr'
#> The following objects are masked from 'package:pryr':
#> 
#>     ast, mem_used
library(tidyft)
#> 
#> Life's short, use R.
#> 
#> Attaching package: 'tidyft'
#> The following object is masked from 'package:pryr':
#> 
#>     object_size
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:tidyft':
#> 
#>     add_count, anti_join, arrange, count, cummean, distinct, filter,
#>     full_join, group_by, groups, inner_join, lag, lead, left_join,
#>     mutate, nth, pull, relocate, rename, right_join, select,
#>     select_vars, semi_join, slice, slice_head, slice_max, slice_min,
#>     slice_sample, slice_tail, summarise, transmute, ungroup
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(tsbox)
library(sparklyr)
#> 
#> Attaching package: 'sparklyr'
#> The following objects are masked from 'package:tidyft':
#> 
#>     distinct, fill, full_join, inner_join, left_join, nest, right_join,
#>     separate, unite, unnest
library(datasets)

EU_stock_tibl <- ts_tbl(EuStockMarkets)

spark_connection <- spark_connect(master = "local")

EU_stock_spark_link <- copy_to(spark_connection, EU_stock_tibl, "EU_stock_spark", overwrite = TRUE)

tryCatch({
  tidyft::object_size(EU_stock_spark_link)
  },
  error = print
)
#> 10.1 Kb

tryCatch({
  pryr::object_size(EU_stock_spark_link)
},
error = print
)
#> <simpleError in object_sizes(list(...), env): bad binding access>

tryCatch({
  lobstr::obj_size(EU_stock_spark_link)
},
error = print
)
#> <simpleError in obj_size_(dots, env, size_node(), size_vector()): bad binding access>

Created on 2021-01-07 by the reprex package (v0.3.0)

hadley commented 3 years ago

Could you please try to make your reprex a little more minimal by only showing the problem with lobstr, and removing anything that isn't directly related? (e.g. the tryCatch() calls).

PinkAppleFlower commented 3 years ago

No problem. I will do it shortly.

Sent from my iPhone

On Jan 7, 2021, at 12:28 PM, Hadley Wickham notifications@github.com wrote:

 Could you please try to make your reprex a little more minimal by only showing the problem with lobstr, and removing anything that isn't directly related? (e.g. the tryCatch() calls).

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

PinkAppleFlower commented 3 years ago

Okay, the new reprex is posted below. Thank you.

library(lobstr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(tsbox)
library(sparklyr)
library(datasets)

EU_stock_tibl <- ts_tbl(EuStockMarkets)

spark_connection <- spark_connect(master = "local")

EU_stock_spark_link <- copy_to(spark_connection, EU_stock_tibl, "EU_stock_spark", overwrite = TRUE)

lobstr::obj_size(EU_stock_spark_link)
#> Error in obj_size_(dots, env, size_node(), size_vector()): bad binding access

Created on 2021-01-07 by the reprex package (v0.3.0)

hadley commented 2 years ago

More minimal reprex:

con <- sparklyr::spark_connect(master = "local")
spark_mtcars <- dplyr::copy_to(con, mtcars, "mtcars", overwrite = TRUE)
lobstr::obj_size(spark_mtcars)
#> Error in obj_size_(dots, env, size_node(), size_vector()): bad binding access

Created on 2022-06-21 by the reprex package (v2.0.1)

hadley commented 2 years ago

More minimal:

con <- sparklyr::spark_connect(master = "local")
lobstr::obj_size(con$state)

Error probably comes from https://github.com/wch/r-source/blob/79298c499218846d14500255efd622b5021c10ec/src/include/Rinlinedfuns.h#L89

hadley commented 2 years ago

Looks like this is an "immediate binding": https://github.com/wch/r-source/blob/79298c499218846d14500255efd622b5021c10ec/doc/notes/immbnd.md#L25

hadley commented 2 years ago

I have a fix that works locally, but making it work properly will be quite a lot of extra effort so unfortunately probably won't make it for this release.

mjsteinbaugh commented 2 years ago

Cool thanks @hadley !

eliotmcintire commented 7 months ago

Are there updates on this?

I am seeing the same error (bad binding access) now with my reproducible package on CRAN with devel versions of R.

I can manually reproduce this with R-devel on my local machines.

The minimal reprex using R-devel is:

lobstr::obj_size(as.environment("package:lobstr"))

This worked with all previous versions of R.

hadley commented 7 months ago

@eliotmcintire can you please file a new issue?

juliasilge commented 7 months ago

I'm seeing this same problem in butcher on R-devel, because of the use of lobstr here. It's not for all models, just for nnet, FWIW.

juliasilge commented 7 months ago

I just used rig to install R-devel and I cannot reproduce the problem locally. 😔

lionel- commented 2 months ago

This also came up in the context of Positron as Ark now vendors a lobstr size implementation:

library(brms)
m <- brm(bf(mpg ~ hp + (1 | cyl), sigma ~ cyl), data = mtcars, seed = 123)
lobstr::obj_size(m)
#> Error in obj_size_(dots, env, size_node(), size_vector()) :
#>   bad binding access

See https://github.com/posit-dev/positron/issues/4686#issuecomment-2352427239.

The tools discussed at useR! with Luke Tierney will be useful for a fix: https://gist.github.com/lionel-/1ebcbd5ec69c0775d514c329522408a3