windows-7rstudioregistryfile-association

Correct the file associations in the registry in windows 7 when a program is deleted


I have a windows 7 operating system and had installed Rstudio in the my documents folder (by just unzipping the .zip file) as I don´t have admin rights to my computer.

I then manually associated the file endings .Rproj .R and .Rmd with rstudio.exe by:

This worked fine, and the files opened automatically in RStudio when I double-clicked on them.

Over the following months, I updated RStudio twice but did not delete the old versions. Then I noticed that the files were always opening in the oldest version of RStudio (the first one that I had installed). I decided to clean up, and deleted the two older versions. At this point, the file associations dissappeared (as expected, since I had just deleted the program they had been associated with).

To associated them to the latest version of RStudio, I repeated the manual steps above, but hit a snag: after selecting rstudio.exe by clicking on the "browse" button within the dialogue box, the program did not appear as an option in the main dialogue box and I could not associate the file with it.

I searched for a solution here and elsewhere but was unable to find one with a complete set of steps that fixed my problem. I did note that this problem is by no means unique to Rstudio, and I suppose can happen to any file endings that have been associated with a program that you have deleted (as opposed to uninstalled?).

I had a suspicion that the path to the old version of Rstudio was stuck in the registry somewhere, but trying various iterations of assoc .Rproj in the command-line didn´t help me:

C:\Users\myusername>assoc .Rproj
File association not found for extension .Rproj

C:\Users\myusername>assoc .Rproj = rstudio
Access is denied.

Also, RStudio was not available in the Default Programs list (accessed from the start menu) and the affected file endings were not listed under File associations either.

I eventually found the solution using windows regedit - but since there doesn´t seem to be a post with the complete steps for this, I have posted it as an answer here, in case anyone else faces the same issue. I had to do this the point and click way, so would be grateful if anyone could provide a solution in the command-line interface, or provide some insight into why I got that "Access is denied" message (which occured even when I tried logging in with a temporary admin account).


Solution

  • It turns out I was right - the old file path was still associated to the file endings in the registry. I was unable to access or edit it from the windows command line prompt, but using the windows regedit program worked, as follows:

    1. Go to the start button, type regedit and click on the regedit program icon to open it.
    2. On the left-hand side menu in regedit, click on the arrow to expand the folder HKEY_CLASSES_ROOT
    3. Scroll down the list to look for the file endings that have become unassociated (in my case this was .R, .Rproj and .Rmd)
    4. Click on one of the unassociated file endings to see what details are recorded for it (these will appear in the right-hand panel of regedit).
    5. See what it says under the Data column for your file ending (in my case, for .R it said “R_auto_file”).
    6. This value (e.g. “R_auto_file”) is the key used to point to the program that will be used to open the file.
    7. Now scroll further down the left-hand menu in regedit, past the zs and keep going until you find a sub-folder with the same name as the key you just identified.
    8. Click on the arrow next to this sub-folder (e.g. “R_auto_file”) to expand it and expand the sub-folders within it (shell and open) until you get to command.
    9. Click on command to view the details in the right-hand panel.
    10. Right-click on the icon that says Default under the column Name in the right-hand panel and select Modify… from the menu that appears.
    11. In the dialogue box that appears, under Value data: you will see an editable file path to the program being used to open the file.
    12. This file path will probably be pointing to the old version of the program that you deleted.
    13. Edit the file path so that it points to the new program, and click ok to save the changes.
    14. Repeat steps 3 – 13 for all file types that have become unassociated.
    15. Restart the computer for the changes to take effect.
    16. You should now see that the files have the program icon next to them and open with the correct version when you double-click on them.