-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix attempt to apply non-function #7
Conversation
FuzzywuzzyR would always return the error "attempt to apply non-function" when calling a function after loading the library. By running reticulate::py_config() beforehand the correct python environments are discovered and the library works correctly.
hi @timonbldw and thanks for the pull request. I took a look also to your message in issue 1.
it will cause problems when submitting to CRAN. R packages that make use of 'reticulate' have to take into consideration that during CRAN checking python might not be installed. Therefore by calling
If you see the examples in the documentation of the package most have the following code snippet for this purpose, try({
if (reticulate::py_available(initialize = FALSE)) {
if (check_availability()) {
........
}
}
Besides using reticulate::py_available(initialize = TRUE) # initializes python bindings
fuzzywuzzyR::check_availability() # checks if the fuzzywuzzyR python dependencies are installed
then you can continue using the fuzzywuzzyR package if the previous 2 commands returned TRUE |
Thanks for your reply! I see, it's likely OS specific in this case. I am using Win10 with conda and Python 3.6.13. I have tried your suggestion before, unfortunately (at least on my OS), it still throws the same error:
> reticulate::py_available(initialize = TRUE) # initializes python bindings
[1] TRUE
> fuzzywuzzyR::check_availability() # checks if the fuzzywuzzyR python dependencies are installed
[1] TRUE
> library("fuzzywuzzyR")
> matcher <- FuzzMatcher$new()
> matcher$Partial_ratio(string1 = "abcd", string2 = "def")
Error in matcher$Partial_ratio(string1 = "abcd", string2 = "def") :
attempt to apply non-function I see that adding |
@timonbldw I'll tell you the truth. Last time that I submitted to CRAN I spent many hours to figure out how to make things work so that I can keep the fuzzywuzzyR package both on Github and on CRAN (I also have other R packages that depend on reticulate and Python). I think that it's not that easy to make an R package communicate with all different versions that exist in Python (I mean also the Conda environments, you can see also issues related to Conda in the reticulate repository) so I'm kind of hesitant to modify something in the .onLoad function that might break things. |
@mlampros I totally see where you're coming from. I'd just add a simple I think I might have found part of the root cause for the issue on Windows 10. When using devtools to import the package (without calling |
I just wanted to inform you that I've added a startup message to the fuzzywuzzyR package (and to all my other R packages that use the 'reticulate' R package to call Python code). You were right that there are cases where the "reticulate::py_config()" is required before loading the fuzzywuzzyR package otherwise the user receives the error 'attempt to apply non-function' (I experienced this error the past week, so I guess something has changed) |
FuzzywuzzyR would always return the error "attempt to apply non-function" when calling a function after loading the library. By running reticulate::py_config() beforehand the correct python environments are discovered and the library works correctly.