How can/should I set my path.expand in RStudio per project? - r

My goal is to have path.expand to be automatically modified as I open a project, so that I don't have to keep writing fread(paste0(getwd(),"foo.csv") every time I load a new file, replacing it instead with fread("~.foo.csv")
I've found this question: address project root in Rstudio
Which seems to suggest that there is a .R_USER file per project in Rstudio. I have successfully been running an R studio project in a folder, and have 'unhidden' the the .Rproj_user folder, however, I am now at a loss to edit it. I'm seeing a tonne of different folders and don't really understand what I can edit, or how.
Is this the right path to expand upon? (jks), or is there a simpler and different way to do this? Is this even sensible? It seems like it is to me, but I'm new to all this, so please do say if this is stupid (and why).

Related

RStudio hangs for a specific project. What file needs to be changed?

I have a project that I've been working on for several months without a problem. Yesterday I tried to profile a bit of code using the raster package that was taking a very long time to run. I left it running overnight and found RStudio unresponsive in the morning. Now when I open that project, I can't do anything except to force quit RStudio. Other projects appear to work fine.
I suspect something bad is stored in the file(s) that remembers where I was. Is there one or more that I can delete and regain control of the project. Candidates in the project folder would seem to be one or more items in the .Rproj.user directory.
I found a tip on the RStudio website. In a terminal, navigate to the project directory and rename .Rproj.user to something different. I used this command - mv .Rproj.user .Rproj.user_old. This keeps the user-specific information around in case you want to go back to it.

R studio not responding

My RStudio is opening multiple processes(opening R Studio in different windows) when I open just one. I am not able to open any project. It becomes unresponsive. I tried using in compatibility mode, running as admin and also uninstalled. But still,(here's the image) the same problem persists. Can someone please help me?
Before you reinstall everything, which may take a lot of time, it is worth removing application data, which is a cache R keeps of last sessions etc. It involves settings such as information from last session, etc which RStudio tries to reopen every time you open it.
For app data, look under your user folder which must be somewhere like
c:\Users\<your_user_here\AppData\Local
c:\Users\<your_user_here\AppData\Local\LocalLow
c:\Users\<your_user_here\AppData\Roaming
Delete every subfolder called R, RStudio-Desktop or RStudio under these folders. Don't worry, you won't lose your source program files and projects. It may help you recover everything without having to start over from scratch.

Power BI Microsoft custom visual locked repo?

This is the link I will be referring to
I'm working with a Microsoft visual on Github. I have found a weird problem. No changes I make to the capabilities.JSON file will apply. I haven't even gotten the script to change. I went in and replaced all instances of the X axis variable with the Y, and vice-versa within the script.r file. Didn't work.
I have deleted the package-lock file, that didn't work. I even opened every single file in this visual folder, searched for the old variables for capabilities, and found nothing.
I went one step further and packaged the file to visualname.pbiviz, converted it to zip, opened the compressed file in a text editor, and still could not find anything that would revert it to the previous names.
The X axis is by default "X axis". I have changed it to be "Duration" in the capabilities.json file, but it will not stick.
If anyone has any insight as to what may be going on, or what Microsoft has done to prevent this visual from being modified, please inform me. I'm especially confused, because Microsoft has labeled this as an open source visual, yet changes are restricted. I'm new to creating/modifying visuals, so perhaps there is something I am just missing. Short of going in and deleting files at random, I'm out of ideas.
I found a way to get this working. I found a bunch of http imports and things like that. What I am assuming was happening is it would ping whatever online repo it was told to, and re-import the files from there before compressing to .pbiviz instead of actually using the files in the visual folder... I copied the two main files I needed (capabilities.json, and script.r) and pasted them into a blank template visual. Everything is working fine and I can continue working on this like normal.
This is based on the assumption that files were being re-imported from an external source before being compressed. If anyone knows for certain what is going on here, feel free to leave an answer.

RStudio R File Corruption

I had a R script open in RStudio. The file was saved many times over the course of several weeks and worked perfectly fine when RStudio was opened and closed. However, today, I restarted my computer and when I opened RStudio and more specifically the script that I mentioned, all of the R code vanished, leaving a single long row of "....." with red highlighting.
When I tried to open the R file in other text processors such as Sublime Text and Notepad++, only a line of zeroes was visible. None of my other R files were affected. I'm currently running Windows 8.1 and have the latest version of R and RStudio. What can I do to recover the code in the file and prevent something like this from happening again?
It might be an old thread and it might have been covered in 'user4458796' answer in suggestion #1 ("Use the history..."), but:
My friend had the same problem and we managed to recover the code from a 'history_database' files located on Windows at:
'C:\Users\%user%\AppData\Local\RStudio-Desktop\'
I assume there is an equivalent location in Linux in general.
Hopefully I won't get downvoted, just sharing my 2cents.
Ben.
It's not clear what happened to corrupt your file (and thus how to fix it if possible) and it is kind of ominous that you're just seeing 0's in other text editors, but I'll give you my best suggestion and some tips.
Suggestions for Attempting Recovery
Since your other R files were unaffected, you should have a messy record of your code in the history. Use the history to reconstruct your code.
Access a copy of your file from any version control, cloud, or offline backup you may have used -- git, SVN, iCloud, SugarSync, Dropbox, etc (I realize you probably wouldn't have posted this question if that were an option, but I had to throw it out there).
Use a Hex or sector editor to try to recover the data.
Use a data recover program to find an old version of your file.
Inspect your trash or recycling bin to see if it has an old version. Depending on your OS and the settings of how you (insecurely or securely) delete files, then you may be able to undelete a deleted version, even if it's not immediately available.
Try different methods of recovering text data from corrupted text files like OpenOffice's and Microsoft's suggestions.
Tips for the Future
I know that hindsight is 20/20, but a few quick tips for good measure:
Use version control. Git is supported in RStudio's GUI interface.
Have more than one version of your file. Many professors and professionals recommend writing/storing code in a text editor and using your IDE only for the working copy.
Make backups. Distinct from #2, you should backup your files to a hard drive, flash drive, or cloud service like Dropbox or Spideroak.

Rstudio opens all files in package after build

Every time I build my package after a modification, R studio will display every file in the package as untitled, and I have to close them and reopen them in order to modify files before another build. To be honest, it doesn't affect functionality that much, but is annoying and can sometimes cause Rstudio to crash.
Has anyone seen this before, and can suggest a fix?
I would post a screenshot, but I am new to stackoverflow and don't have enough reputation (10).
I haven't figured out what caused the problem, but I was able to solve it by deleting all the project files produced by Rstudio (.RProj.user, packagename.Rproj, .Rhistory, .Rbuildignore), and then creating a new project in the existing directory.

Resources