-
Notifications
You must be signed in to change notification settings - Fork 95
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
"Error in (function (x) : attempt to apply non-function" #30
Comments
There are indeed message that may be ignored, or so it seems. But they are very annoying. It is problem that may occur when using Rcpp modules. It is reported in a few other places, but I have not found a solution. They are related to garbage collection. Because of this it is difficult to make a reproducible example. The messages do not occur with small toy data sets (as there is no garbage collection, presumably). Here is an example that I can reproduce or now (from #29)
|
I will just ignore the messages, |
Re-opening because this remains an issue |
Another example. You need
Note that Here is what is actually done under the S4 interface (and some omitted R validity checking)
But running it like this does not produce the messages. |
A similar situation is discussed here for the xcms package. Although that package does not use Rcpp, the messages appear to stem from the mzR package, which does use Rcpp (I believe it has to do with Rcpp modules; see discussion on stackoverflow). |
Not sure if this helps but I am having this issue and can reproduce it like so...
This results in the error and seems to never complete. However...
This works without errors and is very quick... Finally though... This does not reproduce the error - could this therefore be an issue relating to the handling of precision?
I wish I could be more help in diagnosing! |
Okay.. I just updated to the Dev version of {terra} and this no longer hangs but does occasionally print the error message. The previous version I was running was from CRAN on windows 10. |
I get the error message kind of erratically. Most often I re-run the same command and does not complain Using 1.5.24 on
|
@rhijmans Do you know any way to silence these messages as a workaround? Sometimes I write code that produces a lot of them. |
You can ignore these messages from the garbage collector. They do not affect your data. They are very annoying. I have done a lot of things to get to the bottom of this, but sofar to no avail. I have much simpler packages that also show these messages and I need to go back to one of these to create a reproducible example for others to look at (even it only happens on the first run) that does not require installation of GDAL etc. |
I know. I was just hoping for a way to cut down on the terminal spam so I can more easily see my own messages. |
I think you can just wrap the statement with try(..., silent = TRUE), this works for me. Seems like a dirty workaround.. edit: on second thoughts this might not work consistently ~ |
I don't think this error can still be ignored in the latest RStudio (2022.07.1 Build 554). The default behavior is to stop processing scripts upon the first error, even if the error has no consequence in the results. I've had to run the same script twice to get it to finish, after it stumbled the first time while rasterizing vector spatial data. The raster does get created, but the script stops. But then it seems to work well any subsequent time even after clearing objects from memory. |
Can you try again with the current development version (1.6-20) and report back? |
I have installed version 1.6-20 last night. The original script still gets tripped on the same line (though it may have worked the first time). When I remove the offending lines, it trips again on a step subsetting an sf object instead. All the while some spatraster objects are loaded and other functions applies to them. If I move the offending lines to the end, the script didn't trip. I am not sure it is only a terra issue if it trips on the sf object. There is no reason that the order should matter, because the script works when ran again in the same R session (even with prior object loadings wiped). I should also try it on another computer when I get a chance. |
Thanks. This is certainly is related to terra, but since this is related to garbage collection the messages may appear at any time. It would be useful if you could share your script and indicate where they occur though (by private email is fine if you do not want to add it here). |
Here is the issue in the RStudio repository to allow the user to choose the option, rather than stopping the script as the default. As workaround, the previous version of RStudio can be used, |
Thanks @kadyb but |
FWIW I can't reproduce any of the issues reported here on macOS:
Is there something I'm missing? Does this issue only reproduce on certain platforms? |
In my testing (Ubuntu and Windows, using 1.6-19 vs 1.6-20 w/ R 4.2.1) the error-generating code from #218 has been fixed by the added |
@kevinushey with the current CRAN version, this should still give you the messages.
That is #218 which I fixed yesterday. And with that change (a regular call to Also, somewhat the example above has been consistently giving these error messages for a long time, whereas other examples have stopped working (or started to work without error messages) for unknown reasons. |
Thanks; I can reproduce now. I'm trying to see if I can unwind the issue at all... R reference classes (which Rcpp Modules are) register their finalizers here: One can poke a little bit into where finalizers are being registered with something like:
It seems like the finalize method exists when the finalizer is registered...
but that |
Given that the bug goes away with something as simple as:
It's almost surely some kind of GC protection issue. That said, I don't have a good idea as to why the finalize method would be special here; it seems like other methods are just fine, and chasing down protection issues like this is notoriously challenging. Is there any opportunity for |
In principle this doesn't have to be a protection issue. It can be also a race condition between the finalizer and something else in the involved packages. When trying to provoke the problem with higher probability, gctorture may help. It may help to check if anything ever is trying to clear the involved pointers (either by reading the code, or by a debugger watchpoint). Perhaps there is code that cleans up the object, some kind of a destructor, including things that the finalizer needs to run. |
Maybe the issue here is that reference classes initialize methods on instances of their classes lazily, or at least are doing so in this case? For example:
With this code, you'll see output like:
and no errors will occur when the finalizer is run. Maybe the attempt to install the It seems like |
This also fixes the issue:
In other words, explicitly selecting the appropriate |
@kalibera, I think this could be a potential patch for R:
This would force the |
Thanks, that's good to know this makes the bug go away, but we can't add this work-around to base R when we don't know what is the underlying issue (or whether it could be fixed properly, whether is is actually an issue in a package, etc). |
So it looks like this problem has been fixed upstream in As Kevin wrote, more testing and feedback are very welcome. If you want to test it, you need to install: install.packages("Rcpp", repos = "https://rcppcore.r-universe.dev") |
Thanks -- the install command the Rcpp Core team recommend is install.packages("Rcpp", repos="https://rcppcore.github.io/drat") as we make explicit releases to our drat which we consider preferable to random repo snapshots. |
This indeed appears to be fixed with Rcpp-dev and the current terra-dev (where I have removed the calls to |
Yes. Getting Rcpp updated at CRAN is a bit of work given the over 2500 reverse depends so we prefer the bi-annual cycle. But we do maintain a curated repository we recommend for use in the interim. Installing from it is a one-liner install.packages("Rcpp", repos="https://rcppcore.github.io/drat") |
Hi there,
I am receiving the following message using the terra package:
Error in (function (x) : attempt to apply non-function
I call it "message" instead of error because everything seems to work fine. The message appears when I call for the first time in a script a function from the terra package.
I am running the package in a conda installed R version on a HPC cluster. I use to update regularly the package directly from github.
(RH: I moved your second issue to #31)
Cheers
The text was updated successfully, but these errors were encountered: