How to get unsaved script tabs

后端 未结 6 2169
渐次进展
渐次进展 2020-12-13 19:32

I would like to know, if it is possible to get unsaved script tabs in R studio. I accidentally open and switch to new project, then my unsaved scripts disappeared. Can anyo

6条回答
  •  再見小時候
    2020-12-13 19:51

    If someone is still looking for the answer or will look in the future, please read the below working approach


    As far as I Know, there is no straightforward way to restore the unsaved script tabs in the last session or before the Rstudio crashes. The project folder usually contains the hidden folder .Rproj.user with many sub folders, source database is one of them (shortly called as sdb). In the sub folders within sdb having the prefix "s-", you can find almost all the unsaved script tabs in JSON format. You can copy and use them to get the contents of the unsaved script tabs.

    For example, I have a file named BDFFFF92 is present within the project location .Rproj.user/586F3E74/sdb/s-DB8D414F/

    # reading the JSON file
    dataObj <- jsonlite::fromJSON('.Rproj.user/586F3E74/sdb/s-DB8D414F/BDFFFF92', simplifyVector = T)
    

    The actual content in the unsaved scripts will be present in contents of the JSON object.

    # Printing the content from the JSON object
    writeLines(dataObj$contents)
    

提交回复
热议问题