How is to add R and Rtools paths in the environment variable? - r

I have installed R-3.5.1 and Rtools35.exe. But I am unable to install packages in R. Somewhere I got,
Make sure the R and Rtools paths are added in the environment variable.
But I don't know what is environment variable and how is to add R and Rtools paths in the environment variable?
Edit
The answer provided How to add Rtools\bin to the system path in R requires library(devtools). But install.packages("devtools") isn't working.

Installing package that has heavy dependencies just to set environment variables doesn't seem to be good solution.
Below solution is for R 4.0.0 and rtools40.
This uses powershell bash, it should be available on all recent Windows versions.
$ENV:PATH = "C:\R\bin;C:\rtools40\usr\bin;$ENV:PATH"
You can see full R 4.0.0 setup on Windows in this CI yaml.
Note that in powershell it is best to refer to applications using .exe suffix, because powershell has many aliases, so using R or curl will not do what you expect, you need R.exe or curl.exe instead.

Related

Running R from Excel using specific old R packages

First time question asker.
I created an Excel/R tool that uses:
Excel VBA to create a CSV file with data for R,
Launch R using a Windows Shell,
Detects when R is finished running and then
Imports the results in a CSV file created by the R script.
Unfortunately, the R code does not work as programed with some package versions created after 3/1/2020, which creates problems for new users because they cannot just install the current package versions or users who want to use conflicting versions for other projects.
I have a solution for users who do not require newer versions of R for their other work; writing a script that installs all the packages and their dependents using the “versions” package. However, I think this approach will constrain users who want to use newer versions of R. **Is this a correct assumption? **
I thought the {checkpoint} package might offer a good solution. I can get it to run in well in RStudio by creating a RStudio project (where I ran the {checkpoint} package to install the 3/1/2020 versions of my packages). However, I have not found a way to run the R script from the Windows Shell. The R script does not seem to be able to access the packages installed in the RStudio project using {checkpoint}. Does anyone have ideas of how I can have Excel VBA launch the start of the R script in a way that it can assess the packages installed in the RStudio project by {checkpoint}? Perhaps there is a Windows Shell call for RStudio similar to the one I use now for R?
Here is the Windows Shell code I currently use for R in case it helps. It works with the versions approach but not the {checkpoint} approach.
rExeCall = "C:\Program Files\R\R-3.6.2\bin\Rscript.exe"
rExeOptns = " --no-environ --no-init-file --no-restore --verbose "
rscrpt=”Tool.R”
Shell (rExeCall & rExeOptns & rscrpt)
Thank you in advance for your help!
I had hoped that my current R shell code would work when I used {checkpoint} to install the correct versions of the packages in an RStudio project.
I tried specifying the .libPaths to the file location for the RStudio projection (per Running R script from PHP in VSCode not recognizing R packages) without success.

Can renv be used to create a virtual environment with a specific version of R?

I recently installed R 4.0, after previously using relying R 3.6.3. To manage R repositories, I use Rstudio (currently 1.2.5042 on a Windows 10 machine). After upgrading to R 4.0, I opened a project from a few months ago, and realized that Rstudio is now, by default, using the newer version of R (and it's library folder). When running renv::restore(), renv attempts to re-install all libraries in the .lock file for the newer version of R, and I don't see any way to specify that I want to keep using R 3.6.3 and it's associated library.
Coming from a python background, I had assumed that renv would create a virtual environment that isolates both the interpreter and the libraries that the project uses (similar to how anaconda environments are created). However, after looking through the documentation and doing a few searches, I have found no reference to isolating a particular version of R. I have, however, found that Rstudio defaults to using the latest version of R, which is not necessarily the behaviour that I want.
I have tried using anaconda to manage an R environment. However, Anaconda relies on its own smaller repository of R packages, and many of the libraries I need are from researchers that house their code on GitHub.
Is there a way to create an R environment in which I can isolate both the R libraries and the version of R itself? Or, perhaps there is something I am missing about how environments with R/Rstudio are intended to be used?
You are correct that renv only manages the installed R packages, and not the R interpreter itself.
Depending on how you're using RStudio, you can still "fake" this by setting the RSTUDIO_WHICH_R environment variable. For example:
export RSTUDIO_WHICH_R=/path/to/R
rstudio
would tell RStudio to "bind" to the version of R specified by the RSTUDIO_WHICH_R environment variable.
For what it's worth, the ability to bind projects to a specific version of R is a feature of the professional editions of RStudio; however, it's not available in the open-source version. See here for more details.

Which runtime is getting referenced

I have installed R at following location C:\E_Drive\ProgramFiles\R-3.4.3, so I think R environment installed at C:\E_Drive\ProgramFiles\R-3.4.3 will be used when I run the R console, right? Please correct me if I am wrong.
Now, I install a package using the R console.
Now, I download and install RStudio and from the R console of RStudio if I check whether that package is available or not then I see that it is available. I am wondering, how RStudio's R console reported that package is available, I didn't expect that since C:\E_Drive\ProgramFiles\R-3.4.3 is not on my PATH and in no way is linked RStudio with C:\E_Drive\ProgramFiles\R-3.4.3, so I thought RStudio would be referring its own R environment.
Can you please help me understand how my RStudio is referencing the C:\E_Drive\ProgramFiles\R-3.4.3 R environment.
R normally installs packages in the same directory tree as its own binary, but it can also install them elsewhere. On Windows, this generally happens because regular users often don't have write permission in the Program Files directory. The standard Windows installer also records R's location in the registry, so that it doesn't need to be on the PATH to be found by RStudio.
You can find out where Windows or RStudio found R by running R.home() within R. You can find out where R is finding packages in a particular session by running .libPaths().

cygwin aspell installing new language

have a problem with adding new language to cygwin.
As source for language i tried using ubuntu dictionary files.
It would be interesting if anyone could install any non default languages in cygwin spell checker.
The Ubuntu packages use different directories (/usr/lib/aspell vs. /usr/lib/aspell-0.60 on Cygwin), so this isn't going to work. Instead, I suggest you build and install these from the source in one of the following ways:
Download the latest source tarball for your language from http://ftpmirror.gnu.org/aspell/dict/, unpack the tarball, then run ./configure, make, and make install.
Use cygport to build a package for you, then manually install it. For example, create an aspell-lt.cygport file with the following contents:
ASPELL_COMPAT=6
inherit aspell-dict
NAME="aspell-lt"
VERSION=1.2.1.0
RELEASE=1
CATEGORY="Text"
SUMMARY="Aspell Lithuanian dictionaries"
Then run cygport aspell-lt.cygport fetch prep build install package. Such a package would then be fit for contribution to the Cygwin distribution.

How do I install an R package from the source tarball on windows?

The forecast package for R has been updated to version 2.12, but there are currently only windows binarys for 2.11 available on CRAN.
How do I install an R package from the source on Windows?
I know this is an old question but it came up first in my Google search for this same question, even though I knew the answer I just wanted something to copy and paste. Which makes it worth improving the answer for future reference. So here is what works for me:
Install rtools, then:
install.packages(path_to_file, repos = NULL, type="source")
Two answers that may help you avoid the hassle of installing Rtools.
Use http://win-builder.r-project.org/ to build a binary version, download it, and install (using install.packages(...,repos=NULL))
If the package has no binary component (i.e. no src directory with C, C++, or Fortran code that needs to be compiled during installation (not true for forecast, but possibly useful some other time) then simply specifying type="source" within the install.packages call (whether from a repository or a local copy of the source tarball (.tar.gz file)) will install the source package, even on Windows.
Start by reviewing the section on Windows packages in the R Installation and Administration manual, then carefully follow the instructions from The Windows toolset appendix.
I know it's usually bad form to mainly provide links in an answer, but these are links to the canonical references on this topic. I simply link to them rather than summarize their contents, since they should be accurate for the most current R release.
I'm not sure if this is the best way, but I found the following method to work (based in part on the answers above):
1) Download the package .tar
2) Move the package to the directory with your user R libraries (e.g., in my case it was "C:/Users/yourUserName/Documents/R/win-library/3.3")
3) Within Rstudio (or elsewhere, probably), run the command... install.packages("packageName.tar", repos=NULL, type="source")
That worked for me at least. Hope it's helpful!
Download the package *.tar.gz.
make sure you have Rtools installed.
Make sure the R and Rtools paths are added in the environment varialble.
Open a command prompt. Type R CMD INSTALL packagename.tar.gz.
it will work i hope.
To install a package from a .tar.gz file, follow these steps:
Launch R to have the R command prompt
Type: install.packages(<path_to_tar.gz_file>, repos = NULL)
or launch directly:
R CMD INSTALL <path_to_.tar.gz_file>
You need to have R installed but you don't need RTools

Resources