{"action":"closed","issue":{"url":"https://api.github.com/repos/ropensci/magick/issues/70","repository_url":"https://api.github.com/repos/ropensci/magick","labels_url":"https://api.github.com/repos/ropensci/magick/issues/70/labels{/name}","comments_url":"https://api.github.com/repos/ropensci/magick/issues/70/comments","events_url":"https://api.github.com/repos/ropensci/magick/issues/70/events","html_url":"https://github.com/ropensci/magick/issues/70","id":250609340,"number":70,"title":"RStudio bug to detect image NULL pointer","user":{"login":"jeroen","id":216319,"avatar_url":"https://avatars3.githubusercontent.com/u/216319?v=4","gravatar_id":"","url":"https://api.github.com/users/jeroen","html_url":"https://github.com/jeroen","followers_url":"https://api.github.com/users/jeroen/followers","following_url":"https://api.github.com/users/jeroen/following{/other_user}","gists_url":"https://api.github.com/users/jeroen/gists{/gist_id}","starred_url":"https://api.github.com/users/jeroen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeroen/subscriptions","organizations_url":"https://api.github.com/users/jeroen/orgs","repos_url":"https://api.github.com/users/jeroen/repos","events_url":"https://api.github.com/users/jeroen/events{/privacy}","received_events_url":"https://api.github.com/users/jeroen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2017-08-16T12:27:56Z","updated_at":"2017-08-18T10:30:40Z","closed_at":"2017-08-18T10:30:40Z","body":"Saved images in the workspace turn into external NULL ptrs when R is restarted.  However RStudio seems to think these are not NULL and calls the `length()` method which raises an error.\r\n\r\nThe problem is [this line](https://github.com/rstudio/rstudio/blob/3bd734f3a4cf995a5a8d0cc3686ff28557a9e3cb/src/cpp/session/modules/SessionEnvironment.R#L660) in rstudio which does work because our `externalptr` object has a custom class and print method.\r\n\r\n```r\r\n# Create image\r\nlogo <- magick::image_read(\"logo:\")\r\n\r\n# This image is a null pointer\r\nlogo2 <- unserialize(serialize(logo, NULL))\r\n\r\n# However this is FALSE\r\nas.environment('tools:rstudio')$.rs.hasNullExternalPointer(logo2)\r\n```\r\n\r\nThe best solution would be for RStudio to do this in C or C++ something like:\r\n\r\n```c\r\nbool is_null_ptr(SEXP obj){\r\n  return TYPEOF(obj) == EXTPTRSXP && R_ExternalPtrAddr(ptr) == NULL;\r\n}\r\n```\r\n\r\n@jmcphers @kevinushey @jjallaire "}}
{"actor":{"display_login":"jeroen"}}