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

pryr message when displaying an arg value for the first time #50

Open
moodymudskipper opened this issue Jun 21, 2021 · 2 comments
Open
Milestone

Comments

@moodymudskipper
Copy link
Owner

from : #40

c <- function(x) {
  if (x > 0) wat
}
b <- function(x) c(x)
b <- boomer::rig(b, print_args = TRUE)
a <- function(x) b(3)

a(5)
#> 👇 b
#> 💣 c
#> Registered S3 method overwritten by 'pryr':
#>   method      from
#>   print.bytes Rcpp
#> x :
#> [1] 3
#> 💥 c(x)
#> Error: simpleError/error/condition
#> Error in (function (x) : object 'wat' not found
#> 👆 b

We might find a way to trigger this at a more appropriate time.

On the other hand, we use only function promise_evaled, which has nothing to do with print.bytes(), is unexported, and has really simple code, so it might be cleaner just to have it in the package.

Its cpp code is :

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]`
bool promise_evaled(Symbol name, Environment env) {  
  SEXP object = Rf_findVar(name, env);  return PRVALUE(object) != R_UnboundValue;
}

The R code is :

promise_evaled <- function(name, env) {
  .Call('pryr_promise_evaled', PACKAGE = 'pryr', name, env)
}

I find in the repo the old C code, so we can avoid a Rcpp dependency :

SEXP promise_evaled(SEXP name, SEXP env) {  
  SEXP object = findVar(name, env);  
  return(ScalarLogical(PRVALUE(object) != R_UnboundValue));
}

and the R code would be

.Call("promise_evaled", name, env)
@moodymudskipper moodymudskipper added this to the CRAN (0.1) milestone Jun 21, 2021
@moodymudskipper
Copy link
Owner Author

Seems that it should be simple but I can't get it to work.

  • ran usethis::use_c()
  • created C and R functions
  • ran pkgbuild::compile_dll(force = TRUE, register_routines = TRUE)
  • re-document, re-build

the package builds but promise_evaled() crashes the session.

Keeping in separate branch so we can easily revisit later : https://github.com/moodymudskipper/boomer/tree/promise_evaled

@moodymudskipper
Copy link
Owner Author

meanwhile b2539c0 prints the message early so it doesn't clutter the output :

image

changing milestone since we can live with that

@moodymudskipper moodymudskipper modified the milestones: CRAN (0.1), 0.2 Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant