Hello this is likely to be a silly question, sorry for that.
I want to change the library folder in Windows but I do not understand what is said in the cran website:
You may also want to add command-line arguments at the end of the Target field (after any final double quote, and separated by a space), for example --sdi --max-mem-size=1G. You can also set environment variables at the end of the Target field, for example R_LIBS=p:/myRlib, and if you want to ensure that menus and messages are in (American) English, LANGUAGE=en.
When I set the R_LIBS variable in R with R_LIBS="C:/R/i686-pc-linux-gnu-library/3.0" it doen't give any error but the folder path for the library does not change becuse when I type require(package) it is not found.
I saw this post and it says it can be due to the R.profile. I don't know how to deal with the error, should I just remove R and install it from the beginning?
You should set the environment variable R_LIBS in Windows ( not within R) to something like
R_LIBS=C:/R/i686-pc-linux-gnu-library/3.0
Restart R.
Note to set the environment variable you can use setx command:
Open a cmd console (command line console)
setx R_LIBS %R_LIBS%;C:/R/i686-pc-linux-gnu-library/3.0;
Related
I have a student with a Windows 10 machine that has a bad path set for the R_LIBS_USER variable. I went into the R program directory and edited .Rprofile to set to R_LIBS_USER = "". That works until I am in a project using the renv package. renv apparently uses that variable and it brings the brings the bad path back.
I found this SO post and tried to find the variable it in Control Panel (System Properties -> Advanced system properties -> Environment Variables -> User Variables) but I didn't see the key to delete.
I did a full reinstall of R and the problem is still here.... help.
How can I find/erase that bad path is stored in Windows?
Asked on superuser and got crickets, so trying here. This one seems to straddle the border of SU/SO.
In troubleshooting some kind of R configuration issue that was causing a pandoc conversion failure when trying to Knit a .Rmd on a colleague's Windows 10 machine, I noticed that the first path in .libPaths() was pointing to a path on a network directory rather than the c:/Users/[username]/R/win-library/... directory.
Running Sys.getenv() in R showed that HOMEDRIVE and HOMEPATH were (as expected) c: and \Users\[username], yet there was a HOME environment variable listed that was pointing to the network path that we'd found in .libPaths()
Running SET in a cmd shell did not list this HOME environment variable at all, so it seems to be something that R found somewhere else...
Where does R get this HOME environment variable?
FWIW: I fixed the config issue by setting a Windows User Environment variable HOME=%HOMEDRIVE%%HOMEPATH%; R then set all the other environment variables appropriately from there.
R startup is somewhat complicated, but it is pretty well documented. The usual starting place is help("Startup"). The answer to your question is not documented there, but you will find this clue in the See also section:
For the definition of the ‘home’ directory on Windows see the ‘rw-FAQ’
Q2.14. It can be found from a running R by Sys.getenv("R_USER")
and indeed the cited FAQ at https://cran.r-project.org/bin/windows/base/rw-FAQ.html#What-are-HOME-and-working-directories_003f gives us the answer:
The home directory is set as follows: If environment variable R_USER
is set, its value is used. Otherwise if environment variable HOME is
set, its value is used. After those two user-controllable settings, R
tries to find system-defined home directories. It first tries to use
the Windows "personal" directory (typically
C:\Users\username\Documents). If that fails, if both environment
variables HOMEDRIVE and HOMEPATH are set (and they normally are), the
value is ${HOMEDRIVE}${HOMEPATH}. If all of these fail, the current
working directory is used.
You might want to take a look at the here package and, relating to knitr, the ezknitr package. Also, in RStudio, you can specify in the knit menu if the knitting will happen in the current dir, working dir or project dir, as shown here.
Update: let me reiterate the message here since it got downvoted: in a typical usage scenario you don't have to modify the HOME environment variable. Using a proper workflow (e.g. RStudio projects or the here package) is a more robust and portable solution.
So I tried adding R to the path on windows 10 (that is supposedly easy).
System Properties -> Environment variables -> Edit -> new: copy and paste: "C:\Program Files\R\R-3.5.0\bin\x64"
Now the thing is, Powershell just refuses to start the R environment when I type in R. R.exe works apparently. Rgui works as well. Is R a reserved letter in powershell or something? It also seems to repeat the previous command sometimes but that doesn't really seem completely consistent either.
(I put this entry on top of the list of the path and restarted the pc already)
when entering get-alias r I got the following result, so yes "r" is already taken ...
CommandType Name Version Source
----------- ---- ------- ------
Alias r -> Invoke-History
PS: you could remove that alias with remove-item alias:\r from your current powershell session and test if "r" then starts "R.exe". if that works for you, you could edit your profile to remove the alias "r -> Invoke-History" from every new session.
To generalize Guenther Schmitz' helpful answer:
PowerShell has several types of commands, whose precedence is:
Alias
Function
Cmdlet
External application
Note that name resolution is always case-insensitive, so that both r and R refer to the same command.
That is, before R resolves to R.exe, it is not only an r alias that could get in the way, but potentially also a function or a cmdlet (though the latter case is hypothetical, because well-behaved cmdlets follow a <Verb>-<Noun> naming pattern).
Note that built-in aliases shadowing external programs, especially standard ones, is problematic, and in the context of PowerShell Core a discussion is underway about whether to remove all built-in aliases and make them opt-in only - see this GitHub issue.
To see what a given name resolves to, use the Get-Command cmdlet:
# See what R resolves to
Get-Command R
# See ALL commands that R *can* resolve to, with the EFFECTIVE one listed first:
Get-Command -All R
Choices for unambiguously targeting R.exe:
(As you already know) If its folder is in one of the folders listed in environment variable $env:PATH, append .exe - i.e., use the filename extension explicitly:
R.exe ...
Use R.exe's full path (note the need for & for invocation, because the path needs quoting):
& "C:\Program Files\R\R-3.5.0\bin\x64\R.exe" ...
(For the sake of completeness; this is the cumbersome equivalent of using just R.exe): Use Get-Command -Type Application to locate the executable:
& (Get-Command -Type Application R) ...
Alternatively, as stated in Guenther's answer, you could add Remove-Alias r to your PowerShell $PROFILE file in order to remove the built-in alias on session startup, which then allows you to just use r to start R.exe.
Run the following code in your console to install the R package. This code will automatically add R to your os PATH.
sudo apt-get install littler
The tilde expression is not working on my RStudio! I am using a windows 10 OS.
Update : After looking more carefully(thanks to Dason) It seems the "~" is pointing to "user/Documents/" rather then "user/". is there any work around?
Any help?
The home directory in Windows R is set using the environment variable R_USER Set this using Windows (search from the Start Menu for "environment variable"). Whatever you set this to will become what R uses for ~. I have mine set to C:\Users\trehman\R.
Here is how mine looks.
As you found out yourself, R's ~ points to your documents folder. An easy way to work around this could be to start the paths you want to reference with ~/../. So your setwd call would look like this:
setwd('~/../{your actual path from home}')
The same problem occurs on my Windows PC. I do not have a Linux machine at hand to test whether it is the same there. R gets this variable from the R_USER environment variable. You can override that in your R environment startup file. This issue is not specific to RStudio and also occurs when you start an R session from the command line.
At startup, R looks for Renviron.site in the R_HOME directory. Open and edit it
file.edit(file.path(Sys.getenv('R_HOME'), 'etc', 'Renviron.site'))
Define R_USER in that file with the path you want '~' to point to:
R_USER = 'C:/Users/USERNAME'
References:
R for Enterprise: Understanding R’s Startup
When working on a unix system, the ~ expands my directory to my unix home. When on my windows computer, I would like ~ to expand to the drive that is mapped and points to the Unix home. I am using RStudio for coding on the windows computer and it expands the ~ to something that isn't helpful and I am having trouble changing it. I have played with the environment variables and PATH but cannot get it to point to what I want. Any ideas?
UPDATE:
Per Josh's answer. Changing the R_USER environment variable in windows, prior to starting RStudio yields on startup:
Error: invalid version specification ‘NA’
In addition: Warning message:
In utils:::packageDescription(packageName, fields = "Version") :
no package 'rstudio' was found
Changing it manually every time after RStudio startup is possible using this answer but I would like to avoid doing that.
To change the value of ~ from its default, you need to set R_USER before your first call to path.expand() et al. (This is documented in ?path.expand.)
Try this:
## R
Sys.getenv("R_USER")
# [1] "C:\\Users\\Josh"
Sys.setenv(R_USER="C://")
path.expand("~")
# [1] "C://"
To set the starting value of "R_USER" for all of your R/Rstudio sessions, just add a line like the following to your ~/.Renviron or $R_HOME/etc/Renviron.site or wherever you prefer. (As always, see ?Startup for the full set of options.):
R_USER = "C:/"
What is your .libPaths() after starting RStudio? I note that if I start RStudio on Windows without setting R_USER, I get:
> .libPaths()
[1] "C:/Users/Kevin/Documents/R/win-library/3.1"
[2] "C:/Program Files/R/R-3.1.0/library
The first library path is automatically generated by RStudio, and it installs rstudio and manipulate packages there automatically on startup (because it may not have permissions to write to the default, 'system' library).
However, if R_USER is set, then that library path is not set, and this appears to cause problems with the installation of these packages.
I believe you should be able to work around this by also setting the R_LIBS_USER environment variable accordingly -- it should be set to somewhere that RStudio has permissions to write to. See ?libPaths for more information on how that might be appropriately set.
Consider using ${} in Renviron.site to call Windows environment variables. To make R_USER point to each user's document folder, you can put the following in Renviron.site:
R_USER=C:/Users/${USERNAME}/Documents
I have a similar situation and for my needs it was easiest to redefine the HOME-parameter with the line below:
Sys.setenv(HOME="path/to/desired/tilde-folder/")
path.expand("~") # Check that it worked.
Update: Just realised that this solution does not appear to work on my Windows machine, only on a Linux server I was using.