ianmcook commented on a change in pull request #9952:
URL: https://github.com/apache/arrow/pull/9952#discussion_r610784646



##########
File path: r/R/arrow-datum.R
##########
@@ -22,6 +22,7 @@
 ArrowDatum <- R6Class("ArrowDatum", inherit = ArrowObject,
   public = list(
     cast = function(target_type, safe = TRUE, ...) {
+      target_type <- unmask_type_fun(enexpr(target_type)) %||% target_type

Review comment:
       `{{x}}` is shorthand for `!!enquo(x)` which creates a quosure then 
evaluates it. I don't think that works in this context. I tried some various 
other approaches, e.g. just using `enoquo(x)`, using `eval(substitute(x))`, 
etc. (which some of my earlier commits show the history of) but those failed to 
handle all cases. In particular, we want to handle all these cases:
   - `type` is a variable in the calling environment whose value is a 
`DataType` object
   -  type` is a call to a function defined by the user that returns a 
`DataType` object
   - `type` is any arbitrary R expression that the user has wired up to return 
a `DataType` object
   - `type` is a call to a function in another package or in the user's 
environment that masks the Arrow type function of the same name
   
   The `%||% type` part of in `unmask_type_fun(enexpr(type)) %||% type` is 
basically saying "if you tried to defuse `type` and evaluate in the arrow 
package environment but that failed, then give up on the NSE approach and just 
evaluate `type` in the standard way. That was important for enabling the first 
three cases above to work.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to