diff --git a/R/python.R b/R/python.R index d1385e22c..ba001ad1d 100644 --- a/R/python.R +++ b/R/python.R @@ -149,6 +149,12 @@ str.python.builtin.module <- function(object, ...) { if (!is.null(module)) return(module) } + + # convert 'call' to '__call__' if we aren't masking an underlying 'call' + if (identical(name, "call") && + !py_has_attr(x, "call") && py_has_attr(x, "__call__")) { + name <- "__call__" + } # default handling attrib <- py_get_attr(x, name) diff --git a/README.md b/README.md index 1e8cc4d11..82a4c9275 100644 --- a/README.md +++ b/README.md @@ -189,15 +189,14 @@ b <- iterate(iter) # results are empty since items have already been drained Callable Objects ---------------- -In addition to acessing their methods and properites, some Python objects are also callable (meaning they can be invoked with parameters just like an ordinary function). Callable Python objects are returned to R as objects rather than functions (so you can interact with their methods and properties). However, you can still gain access to the callable function using the `as.function` generic method. For example: +In addition to acessing their methods and properites, some Python objects are also callable (meaning they can be invoked with parameters just like an ordinary function). Callable Python objects are returned to R as objects rather than functions, however, you can still execute the callable function via the `$call()` method, for example: ``` r # get a callable object parser <- spacy$English() # call the object as a function -parser_fn <- as.function(parser) -parser_fn(text) +parser$call(spacy) ``` Advanced Functions diff --git a/vignettes/introduction.Rmd b/vignettes/introduction.Rmd index be7944d7a..f4e945fa2 100644 --- a/vignettes/introduction.Rmd +++ b/vignettes/introduction.Rmd @@ -197,15 +197,14 @@ b <- iterate(iter) # results are empty since items have already been drained ## Callable Objects -In addition to acessing their methods and properites, some Python objects are also callable (meaning they can be invoked with parameters just like an ordinary function). Callable Python objects are returned to R as objects rather than functions (so you can interact with their methods and properties). However, you can still gain access to the callable function using the `as.function` generic method. For example: +In addition to acessing their methods and properites, some Python objects are also callable (meaning they can be invoked with parameters just like an ordinary function). Callable Python objects are returned to R as objects rather than functions, however, you can still execute the callable function via the `$call()` method, for example: ```{r} # get a callable object parser <- spacy$English() # call the object as a function -parser_fn <- as.function(parser) -parser_fn(text) +parser$call(spacy) ``` ## Advanced Functions