Can I change the location of Homebrew FFTW install? R can't seem to read FFTW3.h file located in Cellar folder - r

I'm trying to install wholebrain by Daniel Fürth, following the instructions on the macosX install page (available here). I am running MacOS Big Sur 11.5.2, R 4.1.2, and RStudio 2021.09.1.
Unfortunately, the program is not straight-forward to install and requires significant developer tools to work correctly. I'm not a programmer and have almost no experience with coding, so I've been mucking through the instructions for two days now trying to get the install to work correctly and I'm firmly stuck on the final step.
In RS, when I run, devtools::install_github("tractatus/wholebrain", INSTALL_opts=c("--no-multiarch")) I get the following error message:
/bin/sh: pkg-config: command not found filter.cpp:9:10: fatal error: 'fftw3.h' file not found #include "fftw3.h" ^~~~~~~~~ 1 error generated. make: *** [filter.o] Error 1 ERROR: compilation failed for package ‘wholebrain’
I have been trying to figure out what this means for quite awhile now and I think I've narrowed it down to R is not reading the location of the fftw header file from where it was installed by Homebrew. (I could be totally wrong, again- not a programmer)
From what I understand, Homebrew always installs under opt/homebrew/cellar. And, in fact, in there is the compiled fftw program with the needed "fftw3.h" file. But for some reason, RStudio is not able to find and read the file in that location.
From random googling and reading of other posted issues, I think that RStudio may expect the file to be under usr/local/include. Can I just copy and paste the header file into that folder? Or will I be screwing something up if I do that? I am totally intimidated by fftw's description of manual compilation so I don't really want to attempt that. Is there a way to change where R is looking for that header file? I already set my wd to "/" so shouldn't R be able to access any folder on my computer?

I want to post an answer here for anyone who comes after me with the same issue. It came down to RStudio not recognizing the programs Homebrew had installed because it wasn't reading the file location where Homebrew saves them. Homebrew always installs programs in /opt/homebrew/... Here is what I had to do:
In RStudio, open your Renviron file using this command: usethis::edit_r_environ()
In the file that opens (which for me was totally blank), type: PATH=/opt/homebrew/bin:${PATH}, or whatever your particular path you want prepended to the Renviron path is.
Quit RStudio and, when prompted, save. Re-open RStudio and run Sys.getenv("PATH") to check. Your new path (in the example above, '/opt/homebrew/bin') should now be prepended to the list of paths that RStudio will use when looking for programs/files. For me this now looks like /opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/RStudio.app/Contents/MacOS/postback
Finally, I want to say thank you very much to Mark Setchell who really helped point me in the correct direction!

Related

Installation packages no longer found after updating my Mac to 12.2.1

I'm using tcsh shell to access installation packages for my research. After a recent update, my login shell is no longer able to find where those installation files are located. I receive a prompt like this:
!! Attention: GEMC installation check /opt/jlab_software/2.5/Darwin_macosx12.2.1-clang13.0.0/gemc/2.9/gemc not found
Where GEMC is one of several installation files.
I see that it is looking in the directory Darwin_macosx12.2.1-clang13.0.0, which is not where the files are located, but rather they are located in Darwin_macosx12.1-clang13.0.0. I tried creating a symbolic link with the following command:
ln -s Darwin_macosx12.2.1-clang13.0.0 Darwin_macosx12.1-clang13.0.0
But I am still receiving the error informing me that the files are not found. I figured that I incorrectly used the symbolic link (and probably still am) so I pasted in the entire paths in the above command, and still no luck.
I am still kind of a newbie when it comes to Unix commands and navigation, so I apologize if I explained this poorly. That being said, I would really appreciate if someone could help me find a solution to this problem. Thank you in advance!

R: kable_as_image cannot find Ghostscript

I'm re-running some R Markdown scripts that worked fine a month ago, but now kable_as_image is unable to find Ghostscript (yes, I'm on Windows 8). I get the following error message:
Error in kable_as_image(criteria.table,"Criteria",file_format="jpeg"):
Ghostscript is required to read PDF on windows. Please download it here: https://ghostscript.com/
My computer still has Ghostscript, which runs fine when I open it up independently (I tried reinstalling Ghostscript; it didn't help). My guess is that the problem has something to do with R, RStudio, or a package being unable to find the Ghostscript.
I'm pretty sure I've upgraded R in the interim, and I'm currently on 3.4.3 with the latest versions of kableExtra and magick. I've also tried
Sys.setenv(R_GSCMD="C:/Program Files/gs/gs9.22/bin/gswin64.exe")
(and also for gswin64c.exe) but that didn't help, either. Any advice would be appreciated.
Despite what the error message says, R needs the path to MikTeX (or your TeX program of choice), not to Ghostscript itself. The best solution is to add it to PATH in your operating system directly so it's always there, but it also works to add it within R. This is helpful to test it out before digging into your OS (make sure you have the right path), or if you don't have administrator privileges to your work machine.
Sys.setenv("PATH"=sprintf("%s;C:\\Users\\me\\AppData\\Local\\Programs\\MiKTeX 2.9\\miktex\\bin\\x64\\",Sys.getenv("PATH")))
Your path to MikTeX will likely be different than mine. Note that you need sprintf() or something similar to add the directory to the end of the PATH instead of overwriting the existing path.

Cannot run interactive R session from the command line - windows 10

I cannot run a R session from the command line by typing 'R', despite having
C:/Program Files/R
and
C:/Program Files/R/R-3.3.2/bin
in both 'Path' (System) and 'PATH' (User) environment variables (the latter directory is where the actual application is located, I was just trying everything by adding the former).
If I manually change the working directory to C:/Program Files/R/R-3.3.2/bin and type R, a session runs.
Any insight as to why this might be the case? Other programs such as Python 3 run fine, provided the the environment variable is set, why not with R?
This question is part of a larger problem where I am trying to get rpy2 working, but though successfully installed, none of it's basic functions are working, and I thought this maybe to do with a version of R being installed at C:/Users/Anaconda2/R (Because this dir was in Path). The R application installed here would not work when opened, but was the directory returned when I typed R RHOME into cmd - despite the fact this installation is not even functioning, and has apparently only existed since I installed rpy2 a couple of hours ago. I reasoned that rpy2 is trying to use the instance of R installed here rather than my normal one, thus causing the error when I call robjects.r. But this still doesn't explain why I can't run R from cmd. When using R.home(component = "home") from inside a an R session (in RStudio or out of it), it returns my normal, working R directory, at C:/PROGRA~1/R/R-33~1.2. By moving the R file tree installed in Anaconda's directory to a somewhere not in Path, I hoped Windows would find the correct installation via Path - but instead I just get Failed to create process.
My last guess was that Windows didn't like the space in "Program Files", but loads of variables in Path go through the same folder. Any ideas?
I am using:
Windows 10,
R 3.3.2,
Python 2.17.13
UPDATE, PERHAPS SOLVED:
On Josh O'Brien's recommendation (thanks!), I typed where R into cmd, returning:
C:\Users\charl\Anaconda2\Scripts\R.exe
C:\Program Files\R\R-3.3.2\bin\R.exe
The first path is marginally different from the C:\Users\charl\Anaconda2\R listed in my first post (both are in Path), and leads to a third R.exe. It's outside the R file tree located in Anaconda, unlike my standard R installation, but seems to be dependent on it nonetheless. If I remove this R.exe to another location (not in Path), Typing R in cmd will run R from the desired directory, thus fixing the problem. R.home() from inside that session confirms this.
My only remaining concern then; is whether this installation of R in Anaconda necessary for rpy2 or can I just delete it, fixing the original problem? It may just be my ignorance, but I was not conscious that installing rpy2 (I used the standard Windows installer rather than compiling manually) would install another instance of R - is it necessary for the package or just a default/option I failed to omit?

Passing argument to R with Command Prompt [duplicate]

I'm exploring package building on Windows 7 but have been running into trouble after reaching the Command Prompt stage. The following thread appears to be on the same topic that I'm having trouble with, but the question remains unresolved:
Cannot install R package in Windows 7
The problem: whenever I try an R CMD command in Command Prompt (e.g. I've tried R CMD install pkgName, R cmd install pkgName, Rcmd install pkgName, where pkgName is a place-holder for an actual package that has been R CMD checked on OS X and also posted on CRAN, where I have the unzipped source in the current working directory), I get the following error message:
'R' is not recognized as an internal or external command,
operable program or batch file.
(If I try the Rcmd install pkgName command, then the error starts out as 'Rcmd' is not ....) Note that even if I type in just R in Command Prompt and hit enter, I get the same error, so I'm not even able to bring up R here, though it opens perfectly fine in its stand-alone interface.
I have examined the following guides without success in identifying the trouble:
Karl W Broman's website
Rob J Hyndman's website
Steven Mosher's blog
The most immediate thing that came to mind was that the path variables in Windows were not set right, but this also has not (yet) led to the answer. For example, I have triple-checked the paths to ensure they are correct, including for the R version number, that x64 in the path name is accurate, etc.
I realize this is a complex issue to remotely diagnose, but any advice and suggestions on resolving this trouble is appreciated. For reference, below are the steps I have taken already to try to resolve this issue:
Uninstall R and Rtools
Install the latest version of R (2.15.0)
Install Rtools215 to match R version 2.15.0
Originally I let Rtools specify the path variables (turning that option on during installation). No success after this method.
I updated the path variables on my computer, where the below paths were used:
C:\Rtools\bin; C:\Program Files\R\R-2.15.0\bin\x64;
I've also tried the R CMD (and Rcmd) commands with the following paths included (note that these paths don't lead to anything on my computer, so I tried doing R CMD / Rcmd with and without them specified):
C:\Rtools\perl\bin; C:\Rtools\MinGW\bin;
Tried adding/removing the following path, which goes to the only other folder visible within the Rtools folder:
C:\Rtools\gcc-4.6.3;
Tried multiple variations of the R CMD commands, as noted earlier.
I tried this all a few months ago when I had R version 2.14.1 and Rtools214 installed, and I had the exact same trouble.
Note: I already had Cygwin installed prior to R and Rtools, and I have not installed MikTeX (yet).
Have you closed the command prompt and opened a new one after adjusting the PATH?
Enter the command PATH on the command line and ensure that you are properly updating your path
Try navigating to the directory where R.exe is saved and running it locally -- cd C:\Program...\bin\x64, R.exe.
Ensure that you're running on Windows' Command Prompt and not Cygwin's terminal
If you actually have a space after the semi-colon in your PATH, you'll need to remove that: /bin;C:/Program.... Try combining that with Joshua's solution.
I attach my whole solution here:
Install Rtools which is compatible with my R version
Add PATH: C:\Program Files\R\R-2.15.1\bin\x64;C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin
In cmd, enter: R CMD INSTALL packagename
Click "enter", done.
I had a lot of trouble getting this to work, and finally found the golden nugget on r-project (R doesn't like spaces in paths) so here's how I finally did all this:
I installed R to "c:\programs" instead of "c:\program files...". My final path to RSCRIPT.exe is "C:\Programs\R\R-2.15.2\bin\Rscript.exe"
I added that directory to my PATH, but that doesn't seem to help
RStudio is also installed under c:\Programs (e.g. c:\Programs\RStudio), but RTools is installed under the "c:\" root directory (e.g. c:\RTools).
I downloaded all the packages to "c:\downloads\r"
I opened a command prompt in "c:\downloads\r" and ran the R CMD install from this downloads directory, specifying the path to R
e.g. "C:\Programs\R\R-2.15.2\bin\x64\R CMD INSTALL colorspace_1.2-0.zip"
It appears that the CMD processor is Case Sensitive. You have to use INSTALL vs. install
Simple solution, use quotes:
c:> "C:\Program Files\WinZip\wzunzip.exe"
if you run this, you don't need to worry about the space in Program Files.
Hope this help.
I encountered a similar problem while trying to use SparkR from Windows Power Shell. Each time I would do ".\sparkR.cmd" (I was inside the folder containing this file), it would throw an error message like,
cmd is not recognized as an internal and external
command...blah...blah...blah.
I solved the problem by adding "C:\Windows\System32" to my PATH.
I restarted my system and then repeated the process and this time, I saw a new error,
R is not recognized as an internal and external
command...blah...blah...blah.
I tried all sorts of approaches, including the ones mentioned above. NOTHING WORKED, I was probably wasn't efficient enough to make it work.
Then I came across this place at code.google. I simply copied the R.bat onto a notepad, named it as R.bat. Kept it inside the folder where sparkR.cmd was located. For me it was,
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\
The I placed it on my PATH as :
C:\Apache\spark-1.5.1-bin-hadoop2.6\bin\R.bat
Restarted my laptop, opened my Power Shell as an administrator and typed :
.\R.bat help
It worked fine. Then I typed,
.\sparkR.cmd
and there it was.
It worked.
I hope it helps to people new to R. Thank you G. Grothendieck.
In the .bat file add a line of code specifying the path of the folder where R is installed and then give the path of the script as follows -
#ECHO OFF
PATH C:\Program Files\R\R-3.5.1\bin
R CMD BATCH D:\project_abc\helloworld.R
Following this, run the .bat file and you will see the code in the script will run smoothly.
In my case the issue was solved by using Edit instead of New while selecting PATH in the window below:
enter image description here
After selecting Edit I added the directory below:
C:\Program Files\R\R-4.0.2\bin\x64
This solved the issue in my case.

After running R CMD Check, the mypackage.Rcheck directory with PDF manual disappeared

I have installed Rtools v.31 and MKTeX2.9 on my laptop before building my R package. After I ran R CMD check, a directory called mypackage.Rcheck and the source file mypackage_1.x.tar.gz appeared, and while RStudio build package function is checking everything, there is no warning or error message, but at the end when it said (as follows), the corresponding mypackage.Rcheck directory which is supposed to contain the PDF manual disappeared:
checking PDF version of manual ... OK
DONE
NOTE: There were 3 notes.
See
'C:/.../package/mypackage.Rcheck/00check.log'
for details.
R CMD check succeeded
I thought it might be a version conflict between Rtools and R because I'm using R13.1.2 and Rtools v.31, where on the http://cran.r-project.org/bin/windows/Rtools/ website, it said the image isn't frozen (which I don't understand what it means). But I tried all the suggested compatible version pairs between Rtools and R, and still couldn't get it working. So I think this disappearing of mypackage.RCheck is not due to version conflict.
I don't think it's MiKTeX problem because apparently pdf is generated, but was consequently removed. I also tried using --options in R CMD check, but there is no way to force generation of pdf manual, plus pdf was generated at one point. I also read one post on this website, suggesting the use of Rutils function Rd2pdf: "R CMD Rd2pdf mypackage", but I can't run in on windows, and Rutils package is not available for R13.1.2.
can someone suggest the source of the problem or if they have seen this problem before and was able to fix it?
In RStudio: Tools -> Global Options -> Packages. There is a setting "Cleanup output after successful R CMD Check". If this is checked it removes the package.Rcheck folder after a successful check. If you uncheck this setting, the package.Rcheck folder is not removed and you will find the reference manual pdf there.
A common problem for mysterious disappearances of files from R tarballs is to accidentally specify that they should be ignored in the .Rbuildignore file. The lines in that file are regular expressions, so leaving off the anchors ^ and $ can cause them to match more files than you intended. For example,
vig.e
matches vignette.pdf (because there are no anchors to the start and end of the name, and the
dot means "any character".

Resources