network icon indicating copy to clipboard operation
network copied to clipboard

Replace .validLHS() with tryCatch()?

Open krivit opened this issue 3 months ago • 2 comments

The ultimate test of whether something can be assigned to is to actually try assigning to it.

It may therefore make sense to replace the

  if(.validLHS(xn,parent.frame())){  #If x not anonymous, set in calling env 
    on.exit(eval.parent(call('<-', xn, x)))
  }
  invisible(x) 

pattern with the much simpler

  on.exit(try(eval.parent(call('<-', xn, x)), silent = TRUE))
  invisible(x) 

or, since we don't care about the try-error object,

  on.exit(tryCatch(eval.parent(call('<-', xn, x)), error = function(e){}))
  invisible(x) 

Thoughts? @CarterButts ?

krivit avatar Nov 14 '24 04:11 krivit