How to change the default working directory in RStudio - r

I am trying to change the default working directory in RStudio (Version 1.4.1103) in mac ("Wax Begonia" (458706c3, 2021-01-06) for macOS). And I followed the instruction here (How do you change the default directory in RStudio (or R)?). After I change the directory under Tools | Global Options, however, the working directory stay the same even though I restarted RStudio. Is there anything else I could try.
Thank you!

You can set the working directory using setwd(). Inside of setwd() you need to provide the path to the folder you want to be your working directory, such as setwd("C:/Desktop"). I typically set the working directory everytime I open R studio.

Related

Cannot change working directory to folder in windows through R in Ubuntu command line

I have had to install Ubuntu command line on windows10 in order to install R and download a package that is not supported on R for windows. This has worked fine, however, I need to set the working directory in R to the folder containing the files the package needs to work with. I have looked at lots of forums about changing directory and I have no luck!
My default working directory is a hidden folder created by windows when I installed ubuntu command line. I can access this, but I dont need this folder...I need to change the working directory in R to a folder on the D drive on my computer. I have tried to no avail!!
I have tried the normal setwd() command with the following combinations, all of which return the error 'cannot change working directory'
setwd("D:/RNA-seq data/")
setwd("d:/RNA-seq)
setwd("~D:/RNA-seq)
I am really frustrated that I cannot carry out this simple command (maybeI am doing something fundamentally wrong) or maybe this is a limitation because of the hidden default home folder set by windows? Please not I cannot transfer the necessary files in to the default folder created by windows for 'home/R' as it is on the C drive and there isnt enough space on disk. I need to navigate to the folder on d drive in order to carry out my code!!
Any help would be really really appreciated! Many thanks!

Cannot permanently Change R Working Directory - Windows 10

I am running R 3.5.0 64 bit on my Windows 10 laptop.
I can set the Working directory fine for my work space but I am unable to make a permanent change. Each time I reload it, it does not stick.
I changed my Start In file path to the new directory under properties when right clicking the icon.
I have also added setwd() with my file path in the Rprofile.site file
No matter what I do, it continues to revert back to documents when I run getwd() in R when I open it new.
Anyone have any ideas on what I can do to make it stick?
Thanks in advance
You could go the route of using an .Rprofile which is a way to run scripts / commands on startup.
Read about .Rprofile files here in Efficient R Programming
Also, has has been mentioned by #r2evans, if you're using RStudio, there is an option for setting the default working directory. It's under the General section of the Tools -> Global Options menu.

Custom home not working when console run manually (cygwin)

I was trying to set a new home directory for Cygwin, but the thing is I've managed to do so only partially.
I changed the 'db_home:' parameter (cygwin64/etc/nsswitch.conf) to '/windows' so it now matches the win10 default home folder, but the trick works only if mintty.exe was run through cmd.
Running mintty manually with a desktop shortcut results with the very same default directory as if the file was never changed.
Having all that said, I'm a total newbie when it comes to both Cygwin and Unix in general, so it's very likely I missed something obvious.
I appreciate any help provided, thanks in advance.

Issue: Working Directory in R Studio "stuck" on directory containing open R Markdown file

I am using the most recent version of R (3.3.2), running in the most recent version of RStudio (1.0.136) on MacOS Sierra (10.12.3). I am running into an issue in which my working directory corresponds, and is stuck on, the directory that contains the .RMD file I currently have open in RStudio. Upon opening the file, the working directory is correctly set to the directory holding the .Rproj file. When I go to load in a file with a path relative to that directory, however, I get an error that there is no such file in the current working directory, and the error returns the location of the .RMD file as that working directory.
The working directory, however (using getwd()) still reads where the working directory is supposed to be, and no matter where I try to set it, I still get the same error message when I try to read in a file. Notably, I do NOT get an error message that the working directory cannot be changed--R tells me that the working directory has been changed, and that directory is allegedly the current working directory...but it's not.
I have tried fully (as far as I am aware) uninstalling R and R studio and reinstalling them, to no avail. Does anyone have a solution? This is frustrating the heck out of me right now, since I have to revise all the relative paths in the notebooks that I have defined to do my work in the interim.
Extra information in case it's relevant: I restored from a Time Machine backup that I suspect may have been corrupted somehow; some contents of my Applications folder were missing that I had to move over manually. Could this be causing the issue? Are there other system files that R depends on when interacting with the filesystem that I might look to? I'm trying to avoid doing a clean OS install or a piecemeal rebuilding of my files, since I don't know if that's actually the issue.
Thanks in advance!
This is a known feature/bug of RStudio notebooks (Working Directory about halfway down). Notebooks are executed in the same directory as the file. As #Simon Jackson noted, you can change this using knitr::opts_knit$set(root.dir = normalizePath()).

Permanently removing objects in RStudio Mac OS?

Every time I started RStudio, I have seen this my working environment.
I can use rm(list=ls()) to remove them temporarily, but every time I restarted RStudio, they showed up again.
I use getwd() to see my working directory, but in the working directory, I did not see any .Rdata file. How can I get rid of these things ?
Your kind help will be well regarded.
I use Mac OS 10.10.
Click on RStudio in the menu bar and go to Preferences.
In the R General section, unclick the Restore .RData into workspace at startup option.
The default is to reload the working environment when you restart RStudio.
I think that you, at some point, chose to save your environment to your working directory (most likely ~, i.e. your home directory, which is the default RStudio working directory).
The easier way to clear your default environment is to remove the .RData file from your home directory. It will not appear in any Finder window, because in a Unix-like OS (like OS X), files starting with . are hidden. So do the following:
Open a terminal window
If not already there, go to your home folder: cd ~
Check if there's an .RData file: ls -lA .RData
If the file exists delete it: rm .RData (if you want, create a backup: `cp .RData ./RData_backup)

Resources