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

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!

Related

How to change the default working directory in RStudio

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.

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.

Rstudio ignore the R path I manually set but use the deleted one

enter image description here
Even I export the R path to be the correct one, rstudio still use the deleted R path.
I checked my ~/.bashrc file and the deleted path is not in $PATH variable...
Ok , thanks for user 42's answer.
However, I can't find where is .Rprofile located and I've made too many changes to configuration files that it's hard to pinpoint where's the problem any more. I completely erase my disk division and reinstall ubuntu.
My system is ubuntu server so I try to install everything just as user rather than root. And specifically I install R, R-essentials using conda in the directory /usr. This time the Rstudio can find R without problem. Therefore I think Rstudio can only find R in certain directories... like /bin /usr/bin. And somehow it ignores R in other directories.

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()).

Where is the Rserve Config file located on Windows?

I'm using a Windows 7 x64 machine with R-3.1.0. I installed the Rserve package through Rstudio.
The start of Rserve is successful with the following code in Rstudio:
library(Rserve)
Rserve()
I got the following output:
Starting Rserve...
"C:\R\R-31~1.0\library\Rserve\libs\x64\Rserve.exe"
My problem is that I couldn't locate the configuration file. Apparently it can't be "/etc/Rserv.conf".
I did come across a webpage saying that the config file is Rserv.cfg in the working directory (unless changed at compile-time). But which working directory? I have checked the working directory of the current R project as well as the Rserve library directory, but it was not there...Could someone help me with this please? Thank you.
Rserve does not automatically come with a config file, you must make one. Best steps for doing so:
Navigate to the file where you just installed Rserve.exe (C:\R\R-31~1.0\library\Rserve\libs\x64\R, based on the message you copied here)
Find Rserve.exe, Reserve_d.exe, and Rserve.dll there. Copy these files.
Navigate to where R.dll is on your computer. This is probably C:\Program Files\R\R-3.1.3\bin\x64, but may be different depending on where you installed R to.
Copy the 3 files mentioned above to this location.
Create a text file here named "Rserv.cfg" with the arguments you are looking for, such as port 6312 or library(mvoutlier). Yes, I know that this is different from the documentation, but if you start Rserve_d.exe you will see that this is the file it is looking for. I have not had success naming it anything else.
You can start Rserve by specifying the location of the config file. In R instead of just Rserve() try the following:
Rserve(args="--RS-conf C:\\folder\\Rserv.cfg")
If path is more complicated you need to massage it a little bit:
Rserve(args="--RS-conf C:\\PROGRA~1\\R\\R-215~1.2\\library\\Rserve\\Rserv.cfg")
Look in the $RHOME/bin directory
If you can't find it here is a different way to approach it:
Download Rserve at [http://rforge.net/snapshot/Rserve_.tar.gz], and save it in your desired directory
Run R CMD INSTALL Rserve_.tar.gz
This allows you to leave Rserve where you want it.
After looking at the Rserve source code and making some test I found that on Windows platform Rserve try to load the configuration file from the current working directory. Also pay attention because on Windows the file name is RServ.cfg and not Rserv.conf as documented.
The current working directory depends of the process, for example using RStudio by default it is your Documents and Settings folder:
C:\Users\[username]\Documents
but can be changed in the "Global Options" of the IDE
So you can create an "RServ.cfg" text file in that directory with your needed options and starting RServe in the usual way in RStudio
Rserve()
will load your configuration.

Resources