Why is R using system tar, not Rtools tar? [duplicate] - r

This question already has answers here:
How to find correct executable with Sys.which on Windows
(2 answers)
Closed 2 years ago.
I'm trying to debug why I'm suddenly getting the error
tar.exe: Error exit delayed from previous errors.
on running install_github. Thinking there might be a problem with the tar program, I came across this oddity:
> Sys.getenv("PATH")
[1] "C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI2\\wbin;C:\\Rtools\\bin;C:\\Windows\\system32;[...]"
> Sys.which("tar")
tar
"C:\\WINDOWS\\SYSTEM32\\tar.exe"
> file.exists("C:\\Rtools\\bin\\tar.exe")
[1] TRUE
Why is R using the system tar, as opposed to the Rtools-supplied tar, when the Rtools directory is earlier in the path?
OS is Windows 10 2004 (build 19041.330), R 4.0.0.

This appears to be a known problem, for... several years now:
How to find correct executable with Sys.which on Windows
I tried to find documentation for this. I came across this:
https://cran.r-project.org/manuals.html
and in turn this:
https://cran.r-project.org/doc/manuals/r-release/fullrefman.pdf
but it turns out that PDF is specific to Unix, and omits Windows specific parts.
I am not sure of any official Windows PDF. So failing that, you can look at the
source directly:
The search path for command may be system-dependent: it will include the
bin directory, the working directory and the Windows system directories
before PATH.
https://github.com/wch/r-source/blob/92712b53/src/library/base/man/system.Rd#L77-L79
Note on the same page, I also see this:
This interface has become rather complicated over the years: see system2
for a more portable and flexible interface which is recommended for new code.
(If the Windows PDF is hosted in an official place, someone please let me know).

Related

RStudio cannot find the path specified when opening up a script

I have Windows 11, R version 4.2.1, RStudio version 2022.02.3 Build 492, although this problem existed with R 4.1.2 and and older version of RStudio as well, I updated in an attempt to fix it.
For one particular RStudio project (all other project have no problems), I can't open any scripts, and when I try, I get the error "The system cannot find the path specified". While the path is long, it is shorter than the windows file path character limit of 260 characters (it's 230).
This previous question seems similar but is a) more widespread and b) my issue is not fixed by running as administrator.
Additionally, the proposed solution does not seem to apply as my machine does not have a HOME variably in the system variables as described.
There are some other questions with the phrase "the system cannot find the path specified" but none of them seem directly applicable.
Additionally, I can open the script just fine in R or in notepad. It only fails to open in RStudio.

How to build qpdf on Windows?

When running the checks for my R-package (via devtools::check()) I face the warning ''qpdf' is needed for checks on size reduction of PDFs. I found this question were it was suggested (if I understood the answer correctly) to run Sys.which(Sys.getenv("R_QPDF", "qpdf")) and see whether qpdf is found or not. In my case this just returns
qpdf
""
so, I think I didn't install qpdf correctly. Unfortunately it seems to be quite complicated to install qpdf on Windows. My first side question is: does it really is so painful and complicated to install qpdf for Windows or is there an easy solution?
I've followed the instructions until it is said to add C:\MinGW-w64\bin and C:\MinGW-w64\lib\mingw to the PATH variable. But then I don't find further specific instructions to install qpdf, only about how to build qpdf with different other programs. The second side question is: is my assumption correct that after I've build qpdf it is installed? But the real question is: What is the best way to build qpdf? I tried the ./config-mingw32 and ./config-mingw64 commands from the section "Building with MinGW" in my C:\MinGW\msys\1.0\bin\bash.exe but got the error messages ./config-mingw32: No such file or directory and have no idea how to fix this issue.
I'm using Windows 10, R version 3.3.2 Patched (2017-01-07 r71934) -- "Sincere Pumpkin Patch" and RStudio 1.0.136.
You basically do not need to build the file on windows. Please follow three steps below:
Download qpdf for windows from https://sourceforge.net/projects/qpdf/?source=typ_redirect
Extract files in a temp folder
Copy the contents of the bin folder to %SystemRoot%\System32
job done!
Sys.which(Sys.getenv("R_QPDF", "qpdf"))
qpdf
"C:\\WINDOWS\\SYSTEM32\\qpdf.exe"
To flesh out an answer provided elsewhere:
If you are running the 32-bit version of R, it is important that you download the 32-bit version of qpdf, which is the version linked from the SourceForge homepage. If you are running a 64-bit installation of R, you will need to do a bit of digging to locate the 64-bit version of qpdf, which is buried a little more deeply (version 10.0.1 is listed here).
Rather than copying files to C:/Windows/System32, a potentially safer option is to extracted the zipped qpdf directory to C:\Program Files. If you do this, you'll need to add C:\Program Files\qpdf-version_number\bin to your system PATH under the environment variables.
To do this within R, run Sys.setenv('PATH' = paste0('C:\Program Files\qpdf-version_numer\bin;', Sys.getenv('PATH')))
To do this in Windows, open the start menu, type "edit the system environment variables" to open the System Properties, and at the bottom of the "Advanced" tab click "Environment variables". Find the "Path" entry under "System variables" and click "Edit". Then, re-start R so it picks up the modified PATH.
One further step may be required to convince Windows that pqdf is safe to run.
Navigate to C:\Program Files\qpdf-version_numer\bin and execute qpdf.exe (by double-clicking). Windows 10 throws up a security warning, as it's an unrecognized executable file. You'll need to use the more options link to find the button to run the program. This done, Windows will recognize the file as safe to run and allow other software, including R, to use it.

R platform failed to start in Windows 10 when inside directory containing white spaces

I'm working with a software project that requires the portable version of R platform. My intention is to use R in any version of Windows and in any compatible computer.
Problem: In Windows 7, R works fine without any worries, even in portable version. However, in Windows 10 (and probably also in Windows 8), R does not start when put the entire folder inside a directory containing whitespaces (ex.: "C:/Users/Main/Documents/My Folder/RVersion").
In Windows 10, with the absence of spaces, R runs fine. In the presence of spaces, all executable (Rscript.exe, R.exe, etc) except Rgui.exe just open a console and closes instantly. The problem is: I really need that R works in any folder (this is a important part of the project).
Additional information:
I found that R does not work well in directories without the 8dot3 format - and it think that Windows 10 lost this property, which was present in Windows 7. Also, the problem is clear when I run Rgui.exe in a whitespace-containing directory and try to run system("R.exe", intern=TRUE) function: It throws an error indicating that only the part before the first space in directory name was taken into account. Here is the message:
> system("R.exe", intern=TRUE)
[1] "'C:\\Users\\Main\\DOCUME~1\\My' nÆo ‚ reconhecido como um comando interno"
[2] "ou externo, um programa oper vel ou um arquivo em lotes." attr(,"status")
[1] 1
Warning message:
running command 'R.exe' had status 1
Translation of messages [1] and [2]: "'C:\...\My'" not recognized as a internal or external command, nor a program operation or dataset
The same occurs with non-portable version of R, as I already tested.
When I run with a .bat file with the corrected (quoted) directory as input, R.exe runs, but in a disfunctional form and looking like cmd.exe (no R command worked).
I have no ideia how to change variables such as R_HOME to a readable version before R prompt starts.
System/Resources:
Windows 10 Home 64-bit with the last update.
Dell Notebook with Intel i7-5500U 2.40 GHz (not so relevant, I think)
R and R portable 3.3 (last version until this post), downloaded here:
[https://sourceforge.net/projects/rportable/]
I believe that, with the popularity of Windows 10, many other users could face this problem (specially those who depend of R portability).
Thanks in advance!
In the end, I found a plausible solution by myself.
I realized that every time the R.exe is executed in a directory without spaces, the execution is automatically redirected to Rterm.exe. I don't know if they fixed the bug specifically to Rterm.exe in the last version, but this suggests that the Rterm executable is the responsible for opening the R console, and when I tried to execute it directly through a spaces-containing directory, it worked fine (at least in the last R version).
So, in summary, if someone else had this problem, just run Rterm.exe directly.
This resolution is useful enough for those who just depend on R portability, although the Rscript.exe and R.exe still are not working in these conditions. Rscript.exe is useful to execute scripts directly without the need to manually start a new session in a new window, and R.exe redirects to Rterm.exe based on your system, if it is 32-bit or 64-bit (at least as I observed).
Anyway, I already informed CRAN project about this bug, and I hope they check it and fix the issue in the next version. If someone else found an alternative solution, feel free to comment.

Command to see 'R' path that RStudio is using

Original Question
This seems easy and has likely been asked before, but I could not find it via a search.
I have a few flavors of R installed. I simply want to know, when I run RStudio, which flavor of R is it pointing to. So, I need a command -- within RStudio itself, ideally -- that can tell me the underlying R executable that is being used for this RStudio window that I am currently working with.
To be clear, I do not need / want to know the version of R that I'm using (e.g., R version 3.2.2 (2015-08-14) -- 'Fire Safety'). Instead, I want to know the actual path that RStudio is using to get to R -- looking at it from within RStudio -- so that I know "for reals" which version it's using. (E.g., /usr/local/bin/R.)
Edit & Answer
There are a lot of great discussions here, and some are OS-specific. I have a Mac. In my case, I found that:
> system("type R")
R is /usr/local/bin/R
> R.home()
[1] "/usr/local/Cellar/r/3.2.2_1/R.framework/Resources"
> file.path(R.home("bin"), "R")
[1] "/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/bin/R"
As those of you familiar can see, I am using brew. If I look for /usr/local/bin/R outside of R, I see:
$ ls -l /usr/local/bin/R
lrwxr-xr-x 1 mike admin 25 Nov 14 17:31 /usr/local/bin/R -> ../Cellar/r/3.2.2_1/bin/R
which eventually resolves (2 symbolic links) to:
/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/bin/R
as the final destination.
So on my system (Mac OS X), file.path(R.home("bin"), "R") was the most accurate.
(Edited to reflect fact that this is apparently a Windows-specific solution.)
Here on Windows, I'd use the following, for reasons discussed here by Henrik Bengtsson near the start of a long thread on the subject.
file.path(R.home("bin"), "R")
This is better than using file.path(R.home(), "bin", "R") in several settings alluded to in the "Value" section of this snippet from help(R.home):
Details:
The R home directory is the top-level directory of the R
installation being run.
[...]
Value:
A character string giving the R home directory or path to a
particular component. Normally the components are all subdirectories
of the R home directory, but this may not be the case in a Unix-like
installation. [...] The return value for "modules" and on Windows
"bin" is to a sub-architecture-specific location.

PHPUnit shows weird characters as output? [duplicate]

This question already has an answer here:
Strange output from PHPUnit
(1 answer)
Closed 8 years ago.
When I run PHPUnit in Windows on WAMP, I sometimes get weird output like this:
PHPUnit 3.7.22 by Sebastian Bergmann.
Configuration read from D:\MrDWorkspace\Zend\mrdelivery\phpunit.xml
←[41;37mF←[0m.... <-------- this is the weird output
What does it mean?
These are color codes for screen displays. If you are using a simple DOS window, these do not work, and may be turned off from the command line (omit the --colors option). Command Line parameters may be found in the PHPUnit Manual.
It is possible to run a 'smarter' shell in Windows (PowerShell or something) which will then show the colors properly.
You can do this using the ANSICON
Download the ANSICON.
Extract the files to c:\ansicon\ (For
example).
Go to ANSICON folder using "cd c:\ansicon" on the console
(cmd), and then type “ansicon -i” without the quotes.
Add "c:\ansicon" to your path environment variable.
Enjoy!
Note: Windows 32 bits = x86 folder, and Windows 64 bits = x64 folder.

Resources