Skip to content
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

When opening a project, ghost instances of unsaved files are opened #12565

Open
3 of 4 tasks
BartJanvanRossum opened this issue Jan 13, 2023 · 35 comments
Open
3 of 4 tasks

Comments

@BartJanvanRossum
Copy link

System details

RStudio Edition : Desktop
RStudio Version : RStudio 2022.12.1+356 "Elsbeth Geranium" Release
OS Version      : Windows 10
R Version       : 4.2.2

Steps to reproduce the problem

I cannot reproduce this consistently, it seems to happen for some of my projects, but I don't seem a common factor for these projects. If it happens for a project though, it happens consistently

Start an existing project with that contains an unsaved (Untitled1*) file.

Describe the problem in detail

There are 4 Untitled1* tabs in the source panel. Three of these are 'ghost' tabs. Clicking on them will open the first tab. However these ghost tabs cannot be closed.
afbeelding

Describe the behavior you expected

The Untitled1* file opened once

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
@BartJanvanRossum BartJanvanRossum added bug new New incoming issues, ready for initial review. labels Jan 13, 2023
@kevinushey
Copy link
Contributor

Thanks for the bug report! Unfortunately, without a reproducible example it's unlikely we'll be able to make progress here -- can you please share if you're able to divine a set of reproducible steps?

@BartJanvanRossum
Copy link
Author

I completely understand. Let me at least share a visual of what is going on. As you can see I closed all instances of Untitled1, then at around 40 seconds I closed and reopened the project and they were back there again. Somehow the project seems corrupted. Even if I can just manually stop the reopening of these files I would already be helped a lot, even if it is with some workaround. With the situation as it is now, the project becomes more or less unusable.

2023-01-31_8-43-42.mp4

@BartJanvanRossum
Copy link
Author

I ended up throwing away the .Ruser.proj folder which of course fixes the issue. Since this will probably impossible to replicate I will just close it

@ronblum ronblum added projects source editor and removed new New incoming issues, ready for initial review. labels Feb 8, 2023
@ronblum
Copy link
Contributor

ronblum commented Feb 8, 2023

@BartJanvanRossum I'm glad to hear that clearing out the folder resolved the problem in this case. If you run into the issue again, though, please let us know!

@ec363
Copy link

ec363 commented Apr 2, 2023

This also happened to me. I'm not sure what triggered it, I just noticed a few days ago that most my RStudio tabs were duplicates of unsaved tabs, with behaviour exactly as described above. Closed them all manually but they reappeared on RStudio restart, even after I had unchecked 'Restore previously open source documents at startup' and 'Restore RData at startup' and restarted RStudio again.. After finding this issue thread and scratching my head about which file I should remove (I wasn't in an R project..), I seem to have solved it for now, but the only additional actions I took were to Clear Project List on the dropdown menu and quit/reopen RStudio several times... I'm on Mac OS 13.2.1, RStudio 2022.12.0+353.

@ronblum
Copy link
Contributor

ronblum commented Apr 3, 2023

@ec363 Thanks for bringing this to our attention! I'll reopen the issue.

@ronblum ronblum reopened this Apr 3, 2023
@github-actions
Copy link

github-actions bot commented Oct 1, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

@github-actions github-actions bot added the stale Issues which have been closed automatically due to inactivitiy. label Oct 1, 2023
@github-actions
Copy link

This issue has been automatically closed due to inactivity.

@befriendabacterium
Copy link

befriendabacterium commented Jan 20, 2024

Hey folks, I think I may have finally gotten to the bottom of this after years of just dealing with it...

Essentially, the issue is related to the .Rproj.user folder. If you delete that (I was a bit scared to at first but it appears to be safe to do so...https://stackoverflow.com/questions/57790236/what-is-rproj-user-and-can-i-safely-delete-it), then all your problems will be solved, I think. Or at least they were for me!

In terms of why this works, I'm not 100% but I have two, potentially interacting, theories:

  1. People like me, @BartJanvanRossum and @ec363 created their RProjects with Global Options > General > Basic with 'Restore RData into workspace at startup' ticked. This changes the content of the .Rproj.user folder somehow, causing it to keeps restoring old files when you open your project. Notably, changing the options after the creation of the project doesn't seem to fix the issue - implying a missing link where RStudio should be updating .Rproj.user with the new settings. Why it restores a random bunch of ghost files I'm not sure but it might be because...

  2. Cloud services like OneDrive are corrupting the .Rproj.user folder content. This may be because it saves the version history of files, or something else. Somehow, somewhere, data on the ghost files are kept and RStudio is almost randomly selecting files from this graveyard to restore when you open your RStudio Project.

I still don't fully hand how it's all (not) working and it may be something approximating one of the theories, both of them, or neither. What might help us get closer to an answer is is @BartJanvanRossum and @ec363 could confirm:

  1. What (they think) their Global Options > General > Basic options were set to when they made their projects,
  2. Whether they are both working on OneDrive (like me), or Dropbox, or another cloud drive?

Anyways, we have a workaround but would be great to get a permanent fix for this tricky, hard to reproduce issue!

Cheers
Matt

P.S. Thanks to @nirgrahamuk on Posit Community for pointing me to this thread when I re-raised the issue here https://community.rstudio.com/t/opening-rproject-opens-old-scripts-including-previously-discarded-ones/179687/2

@BartJanvanRossum
Copy link
Author

Thanks for diving further into this. Answering your questions

  1. This is indeed my default setting I use when creating new projects
  2. I don't work on OneDrive, Dropbox or anything similar when working on R projects. So far I always had this problem on my work computer and there I have my projects on my C drive.

For me this is not happening anymore for projects created in recent versions of RStudio, i.e. in versions starting from the one I mentioned in the original post. It happened (and still sometimes happens) in projects that were created in an earlier version and then opened in the latest version of RStudio.

The ghost files for me don't seem to be random files. The files that I hadn't saved yet when closing the project are the files that are duplicated. One extra instance of each of these files is added when reopening the project.

@befriendabacterium
Copy link

Hi Bart

Thanks for getting back to me so quickly. I was already having second thoughts about theory 2 to be honest - so maybe it's nothing to do OneDrives, Dropbox etc. Though the discrepency with the randomness of files is odd. I would say that mine does alightly prefer recent files but often opens up some random ones too. Often files opened are unsaved ones and there are duplicate versions of the same file, causing RStudio to prompt me to 'reload the file from disk'.

In terms of what version of RStudio I'm running, it's:

RStudio 2023.06.1+524 "Mountain Hydrangea" Release (547dcf8, 2023-07-07) for windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2023.06.1+524 Chrome/110.0.5481.208 Electron/23.3.0 Safari/537.36

But as you imply, it may be more about what version of RStudio was used to create the project (and hence .Rproj.user folder), than what version of RStudio you are currently running. Perhaps it is resurrecting an old bug in RStudio that has since been fixed. Either way, it's all very occult.

Cheers
Matt

@mezaronald
Copy link

Hey guys,

I was having the same problem, so I tried to find a directory who stores the RStudio Session. In my case was the following one:
C:\Users[user]\AppData\Local\RStudio\sources
And find a folder named 'session-[alphanumerics]'
I closed RStudio and deleted the folder (in my case contained more than 1,000 files). The next time I reopened the program, a new, clear session was loaded.

Regards

@befriendabacterium
Copy link

Hey @mezaronald,

Great to have your contribution to this too! Not only does it help reassure me that this hard-to-reproduce issue is real and it's not just me going mad, but it hopefully all of our pieces of information provide enough evidence for the RStudio devs to figure out what's actually going on here!

I also have this folder with the same file path structure. It seems to be a temporary folder storing information on the files currently open in RStudio (when I closed one of my RStudio sessions, the folder disappeared). So perhaps there is some interaction between the .Rproj.user folder and the 'session-[alphanumerics]' one which is causing this issue, and deleting one severs the link, solving the problem? I assume that 'session-[alphanumerics]' is created temporarily for projects which you are saving history for, and then the contents gets transferred to .Rproj.user or something?

@ronblum would be great if you could give some additional clarity on this please, so that perhaps this can be resolved internally within RStudio, instead of with our workarounds (which may have some risks associatd with them)?

Anyways, great to get people talking on this sticky issue, feel like we're making progress together! 🕵️

Cheers
Matt

@ec363
Copy link

ec363 commented Jan 27, 2024

Hi all,

My answers are the same as @BartJanvanRossum 's. Additionally, I too am no longer afflicted with this strange issue, and my memory of it also was the ghost files were duplicates of unsaved files.

My only addition would be that I work a lot outside the context of an active Rproject, and I'm certain this issue flared up in one of those sessions. Not sure if this helps!

Eszter

@kevinushey kevinushey reopened this Jan 27, 2024
@kevinushey
Copy link
Contributor

Re-opening for further investigation.

@kevinushey kevinushey added this to the Chocolate Cosmos milestone Jan 27, 2024
@gtritchie gtritchie removed the stale Issues which have been closed automatically due to inactivitiy. label Jan 29, 2024
@befriendabacterium
Copy link

befriendabacterium commented Jan 30, 2024

I regret to report that the problem has resurfaced. Implemented the workaround of deleting the .Rproj.user folder again successfully (@mezaronald's solution didn't work for me - the said folder wasn't even there this time despite having the project open). This time the ghost files were not unsaved files but some saved files I previously had open in the project (despite my settings being set to not re-open/save history). Possibly triggered by opening the same project in two different RStudio sessions, but not sure.

Good to see @kevinushey has opened it for reinvestigation though.

@kevinushey
Copy link
Contributor

To check once more -- has anyone found a way to reliably reproduce this issue?

@befriendabacterium
Copy link

Hi Kevin,

No, I haven't been able to create a reproducible example yet unfortunately. Very hard to reproduce and I can't share the project it's affecting because it's confidential. I have a test project that I'll try to bash enough to reproduce the issue and share if I manage it, but no promises sorry.

Cheers
Matt

@kevinushey
Copy link
Contributor

kevinushey commented Feb 2, 2024

Thanks -- if you're able to reproduce successfully in a project you're able to share, it would be very helpful if you could e-mail me the (zipped or tarred) contents of your .Rproj.user folder, at kevin <at> posit <dot> co. Note that this folder will contain RStudio's internal cache of files you had opened in the project, alongside console output, so you may want to double-check that it does not contain any confidential information before sharing.

@espinielli
Copy link

espinielli commented Mar 4, 2024

Same issue here...the Untitled panes resurface even after I closed all of them without saving.
If I keep any of them they come in duplicates with a ghost one which you cannot select.
Deleting .Rproj.user solves the issue.

Machine

MBR Apple M1 Max
macOS 14.3 (23D56)

RStudio

RStudio 2023.12.1+402 "Ocean Storm" Release (4da5832, 2024-01-29) for macOS
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2023.12.1+402 Chrome/116.0.5845.190 Electron/26.2.4 Safari/537.36

@befriendabacterium
Copy link

befriendabacterium commented Mar 4, 2024

Yeah...in some cases I am now getting it even without an RProject open (even with Global Options set not to reopen old files). Though the problem seems worse/more frequent with projects. Still unable to get a reproducible example for you together though, i'm afraid sorry

@balthasars
Copy link

balthasars commented Mar 11, 2024

Also having the same issue here on Windows, also resolved by deleting the .Rproj.user/ directory. However, in my case it only happens after RStudio crashes. Will try to provide reproducible example when this happens again.

@kevinushey
Copy link
Contributor

@balthasars thanks -- but even if I simulate a crash for RStudio with something like:

taskkill /IM rsession-utf8.exe /F

as invoked from a Command Prompt, I still don't see the ghost tabs. Can you provide any other details; for example, when the crashes are occurring and why?

@befriendabacterium
Copy link

befriendabacterium commented Mar 11, 2024

Hi Kevin

Short of being able to produce a reproducible example, is there a way I can send you some traceback source code showing what RStudio is doing in the background when this happens or something? That might be more achievable.

cheers
Matt

@balthasars
Copy link

balthasars commented Mar 19, 2024

@balthasars thanks -- but even if I simulate a crash for RStudio with something like:

taskkill /IM rsession-utf8.exe /F

as invoked from a Command Prompt, I still don't see the ghost tabs. Can you provide any other details; for example, when the crashes are occurring and why?

@kevinushey
I can't really make out a general pattern yet but the crashes of RStudio only happen upon restarting R using my shortcut for Restart R Session. Will have to check if it correlates with more than one RStudio session being open in the background, but I don't think that necessarily needs to be the case.

@kevinushey
Copy link
Contributor

I can't really make out a general pattern yet but the crashes of RStudio only happen upon restarting R using my shortcut for Restart R Session.

Thanks -- I'm also curious if it might also depend on what R packages if you loaded in the session, or what kind of data / objects you're using in the session. What packages are you using most commonly?

@balthasars
Copy link

I can't really make out a general pattern yet but the crashes of RStudio only happen upon restarting R using my shortcut for Restart R Session.

Thanks -- I'm also curious if it might also depend on what R packages if you loaded in the session, or what kind of data / objects you're using in the session. What packages are you using most commonly?

So the output of sessionInfo() will usually look like this:

R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=German_Switzerland.utf8  LC_CTYPE=German_Switzerland.utf8    LC_MONETARY=German_Switzerland.utf8 LC_NUMERIC=C                        LC_TIME=German_Switzerland.utf8    

time zone: Europe/Zurich
tzcode source: internal

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] jrvFinance_1.4.3  vcd_1.4-12        highcharter_0.9.4 quantmod_0.4.26   TTR_0.24.4        xts_0.13.2        openxlsx_4.2.5.2  jsonlite_1.8.8    e1071_1.7-14      gtable_0.3.4      gridExtra_2.3    
[12] devEMF_4.4-1      extrafont_0.19    zoo_1.8-12        RODBC_1.3-23     

loaded via a namespace (and not attached):
 [1] constructive_0.3.0 htmlwidgets_1.6.4  rlist_0.4.6.2      lattice_0.22-5     vctrs_0.6.5        tools_4.3.3        generics_0.1.3     curl_5.2.1         tibble_3.2.1       proxy_0.4-27       fansi_1.0.6       
[12] pkgconfig_2.0.3    data.table_1.15.2  assertthat_0.2.1   lifecycle_1.0.4    compiler_4.3.3     stringr_1.5.1      keyring_1.3.2      htmltools_0.5.7    class_7.3-22       yaml_2.3.8         Rttf2pt1_1.3.12   
[23] crayon_1.5.2       pillar_1.9.0       extrafontdb_1.0    tidyr_1.3.1        MASS_7.3-60.0.1    openssl_2.1.1      tidyselect_1.2.1   zip_2.3.1          digest_0.6.35      stringi_1.8.3      dplyr_1.1.4       
[34] purrr_1.0.2        rprojroot_2.0.4    fastmap_1.1.1      here_1.0.1         colorspace_2.1-0   cli_3.6.2          magrittr_2.0.3     utf8_1.2.4         broom_1.0.5        waldo_0.5.2        backports_1.4.1   
[45] lubridate_1.9.3    timechange_0.3.0   httr_1.4.7         igraph_2.0.2       askpass_1.2.0      chk_0.9.1          lmtest_0.9-40      rlang_1.1.3        Rcpp_1.0.12        glue_1.7.0         rstudioapi_0.15.0 
[56] R6_2.5.1           fs_1.6.3          

It's a messy legacy environment where many libraries are loaded using library() calls, followed by source() calls to 8 massive function files (each of which is many 1000 lines long) that puts 800+ functions into the global environment 🤡. So RStudio is often a bit slow (I will be happy to have everything in an R package soon) ).

@befriendabacterium
Copy link

Posting my session info in case helpful to find similarities. Maybe others in thread can do same?

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_United Kingdom.utf8  LC_CTYPE=English_United Kingdom.utf8   
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.utf8    

time zone: Europe/London
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
  [1] tidyselect_1.2.0    Exact_3.2           rootSolve_1.8.2.3   libcoin_1.0-9      
  [5] dplyr_1.1.4         fastmap_1.1.1       TH.data_1.1-2       mathjaxr_1.6-0     
  [9] digest_0.6.33       rpart_4.1.19        lifecycle_1.0.4     cluster_2.1.4      
 [13] multcompView_0.1-9  survival_3.5-5      lmom_2.9            magrittr_2.0.3     
 [17] compiler_4.3.1      rlang_1.1.1         Hmisc_5.1-0         tools_4.3.1        
 [21] utf8_1.2.4          data.table_1.14.8   knitr_1.45          htmlwidgets_1.6.2  
 [25] here_1.0.1          plyr_1.8.8          multcomp_1.4-25     polspline_1.1.23   
 [29] expm_0.999-7        withr_3.0.0         foreign_0.8-84      numDeriv_2016.8-1.1
 [33] nnet_7.3-19         grid_4.3.1          stats4_4.3.1        fansi_1.0.6        
 [37] e1071_1.7-13        colorspace_2.1-0    ggplot2_3.4.4       scales_1.3.0       
 [41] MASS_7.3-60         cli_3.6.1           mvtnorm_1.2-2       rmarkdown_2.25     
 [45] metafor_4.5-9       rms_6.7-0           generics_0.1.3      rstudioapi_0.15.0  
 [49] httr_1.4.7          tzdb_0.4.0          readxl_1.4.3        gld_2.6.6          
 [53] proxy_0.4-27        stringr_1.5.1       modeltools_0.2-23   splines_4.3.1      
 [57] metadat_1.2-0       parallel_4.3.1      cellranger_1.1.0    rcompanion_2.4.30  
 [61] matrixStats_1.0.0   base64enc_0.1-3     vctrs_0.6.5         orchaRd_2.0        
 [65] boot_1.3-28.1       Matrix_1.6-1        sandwich_3.0-2      SparseM_1.81       
 [69] hms_1.1.3           patchwork_1.1.3     Formula_1.2-5       htmlTable_2.4.1    
 [73] beeswarm_0.4.0      nortest_1.0-4       glue_1.6.2          codetools_0.2-19   
 [77] stringi_1.8.3       gtable_0.3.4        lmtest_0.9-40       munsell_0.5.0      
 [81] tibble_3.2.1        pillar_1.9.0        quantreg_5.96       htmltools_0.5.6    
 [85] R6_2.5.1            rprojroot_2.0.4     evaluate_0.23       lattice_0.21-8     
 [89] readr_2.1.4         backports_1.4.1     MatrixModels_0.5-2  class_7.3-22       
 [93] DescTools_0.99.49   Rcpp_1.0.11         gridExtra_2.3       nlme_3.1-162       
 [97] checkmate_2.2.0     xfun_0.40           coin_1.4-2          forcats_1.0.0      
[101] zoo_1.8-12          pkgconfig_2.0.3 

@BartJanvanRossum
Copy link
Author

I think I now got a project that consistently doubles the amount of unsaved files every time it is opened.
It is a project for a package that is on CRAN so I could share the full project. However the .Rproj.user directory which I assume is important for diagnosing what is going on is close to 500MB, so even after zipping it is a lot larger then the 25MB github allows for attached files. I could use surffilesender or something similar to share the files. Would that be workable?

@kevinushey
Copy link
Contributor

I could use surffilesender or something similar to share the files. Would that be workable?

That would be perfect -- thanks!

@BartJanvanRossum
Copy link
Author

This should be it. Link is valid until May 20.
https://filesender.surf.nl/?s=download&token=89d75e51-ba0a-4328-913d-fb6b77b348ee

@kevinushey
Copy link
Contributor

Thanks! I'm still not able to reproduce using that project, though. When I open the project, I see three untitled documents (Untitled1, Untitled2, Untitled3), each with different contents. However, closing and re-opening the project doesn't trigger any new Untitled documents to be opened. Am I missing any steps?

@BartJanvanRossum
Copy link
Author

No, those are exactly the steps I use to reproduce the problem. If I open the project I get two instances of the three untitled documents, if I then close and reopen I get three instances. I can remove the ghost instances, but then closing and reopening RStudio brings them back again.

One thing I did notice this morning was that after upgrading to R4.4 and then upgrading RStudio to a Chocolate Cosmos daily build because of issues related to #14590, the ghost instances didn't appear anymore. Because of the unpredictable nature of this issue I don't think it is a guarantee that it is actually fixed, but my hopes are up (a bit).

@ronblum
Copy link
Contributor

ronblum commented May 1, 2024

@BartJanvanRossum Fingers crossed that this truly resolves the issue! Also, did you grab build 2024.04.0+735? If not, I would switch to it, since that's the supported build that was just released.

@BartJanvanRossum
Copy link
Author

Somehow I missed the released build. I got 2024.04.0+737. Probably very similar so for now I will stick with this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants