R fatal error on using readr package

Hi, I'm writing my own package to look at some real estate pricing (e.g. predict pricing for an apartment based on historical sales data). In my package, I have written functions that make use of some readr functions e.g. readr::read_csv(), readr::parse_number().

The issue I'm having is that RStudio is throwing a R encountered a fatal error message when I run one of my functions that makes a call to a readr function. (I've isolated it to readr calls by commenting/uncommenting code). I am able to repeat the error on a new RStudio session when I Install and Restart my package. If I do a Load All call, then the error does not occur.

I've outlined the steps I have taken so far below and have included the last few lines of my C:\Users\Tom\AppData\Local\RStudio-Desktop\log\rsession-Tom.log log file.

I have also gone through the same steps on my Macbook, and using only the R GUI on Windows, and the error does not occur. Hence, it looks to me like it is a Windos RStudio issue?

Any suggestions on where to look / try next to diagnose the issue?

Steps taken:

  1. install.packages("readr") (completes successfully)
  2. Document from the RStudio Build\More menu window (completes all ok)
  3. Check from the RStudio Build window (completes 0 errors, 0 warnings and 1 note on no visible binding for global variables '.' and the package internal data sources)
  4. Install and Restart from the RStudio Build window
  5. Run my custom package with a function that makes a call to readr::function
  6. RStudio notification of R fatal error
  7. Repeat Install and Restart from the RStudio Build window
  8. Load All from the RStudio Build\More menu window
  9. Run my custom package with a function that makes a call to readr::function
  10. No fatal error

Windows system config:
RStudio v1.3.1093 (have done uninstall, download, install)
R x86_64 v4.0.3 (have done uninstall, download, install)
Windows 10 Home v2004 build 19041.572

Mac system config:
RStudio v1.3.1093
R v4.0.3 x86_64 v4.0.3
MacOS High Sierra v10.13.6

Log file:

04 Nov 2020 18:40:32 [rsession-Tom] WARNING Invalid values found in C:/Users/Tom/AppData/Local/RStudio/rstudio-desktop.json: /export_viewer_options/format, /export_viewer_options/viewAfterSave, /export_viewer_options/copyAsMetafile; LOGGED FROM: class rstudio::core::Error __cdecl rstudio::session::prefs::PrefLayer::loadPrefsFromFile(const class rstudio::core::FilePath &,const class rstudio::core::FilePath &) src/cpp/session/prefs/PrefLayer.cpp:165
04 Nov 2020 18:40:41 [rsession-Tom] ERROR system error 10053 (An established connection was aborted by the software in your host machine) [request-uri: /events/get_events]; OCCURRED AT void __cdecl rstudio::session::HttpConnectionImpl<class rstudio_boost::asio::ip::tcp>::sendResponse(const class rstudio::core::http::Response &) src/cpp/session/http/SessionWin32HttpConnectionListener.cpp:113; LOGGED FROM: void __cdecl rstudio::session::HttpConnectionImpl<class rstudio_boost::asio::ip::tcp>::sendResponse(const class rstudio::core::http::Response &) src/cpp/session/http/SessionWin32HttpConnectionListener.cpp:118
04 Nov 2020 18:40:46 [rsession-Tom] WARNING Invalid values found in C:/Users/Tom/AppData/Local/RStudio/rstudio-desktop.json: /export_viewer_options/format, /export_viewer_options/viewAfterSave, /export_viewer_options/copyAsMetafile; LOGGED FROM: class rstudio::core::Error __cdecl rstudio::session::prefs::PrefLayer::loadPrefsFromFile(const class rstudio::core::FilePath &,const class rstudio::core::FilePath &) src/cpp/session/prefs/PrefLayer.cpp:165
04 Nov 2020 18:40:57 [rsession-Tom] WARNING Invalid values found in C:/Users/Tom/AppData/Local/RStudio/rstudio-desktop.json: /export_viewer_options/format, /export_viewer_options/viewAfterSave, /export_viewer_options/copyAsMetafile; LOGGED FROM: class rstudio::core::Error __cdecl rstudio::session::prefs::PrefLayer::loadPrefsFromFile(const class rstudio::core::FilePath &,const class rstudio::core::FilePath &) src/cpp/session/prefs/PrefLayer.cpp:165

Im curious about what this file contains, can you share it here ? (and why it might have been set to contain invalid values)
I wonder whether if we edit those values out, your issues may resolve.... :thinking:

This is likely due to an interaction with the cpp11 package and RStudio's method of restoring sessions used in 'Install and Restart'.

It has been reported and fixed in the development repository (https://github.com/r-lib/cpp11/issues/121), but was not submitted to CRAN until today.

Once the readr package binaries have been recompiled with this version of cpp11 this should be resolved. In the meantime you can also install the development version of cpp11 and recompile readr locally to fix the issue.

I apologize for the bug and hopefully this clears up how to resolve it.

1 Like

nirgrahamuk the contents of rstudio-desktop.json when the error occurs is:

{
    "context_id": "D4845A97",
    "error_handler_type": "break",
    "export_viewer_options": {
        "width": 1814,
        "height": 738,
        "keepRatio": false
    },
    "theme": {
        "name": "One Dark Syntax theme",
        "url": "theme/custom/local/One%20Dark%20Syntax%20theme.rstheme",
        "isDark": true
    }
}

Note the use of a custom theme (intended to replicate the Atom One Dark UI theme). I tried the default theme and several others that come with RStudio, and the error still occurs.

jimhester Will do as you suggest and report back if that resolves the issues.

FYI to update on the sequence of events to get the error:

  1. New session of RStudio
  2. Install and Restart my custom package
  3. I have a script that calls functions from my package to run through some analysis. In the script there is an import call at the start (import::from(magrittr, "%>%")) to import the pipe operator for use in the script.
  4. The readr function calls occur all ok....until
  5. Install and Restart my custom package again
  6. Run the import call again, R then throws an error Error: Cannot assign name to different value in the given environment. Name already in use
  7. Now, when my package calls a readr function, the R fatal error occurs

Quick update, have installed the GitHub versions of cpp11 and readr, and recompiled readr. I no longer seem to be getting the fatal error, so looks like issue solved! Thank you @jimhester

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

curious if we compare the rstudio-desktop.json now to how it was previously ?
or it was a red herring ! Happy for you the jimhester's solution worked :slight_smile:

same problem, Jim's solution doesn't help

@nirgrahamuk the json without the custom theme is the same but does not have the "theme" tag. I think it was a herring of red colour!