Install R 3.x via homebrew - r

The R formula https://github.com/Homebrew/homebrew-core/commits/master/Formula/r.rb was upgraded from version 3.6.3 to 4.0 semi-recently. There are a few backward-incompatible changes in version 4, so I would like to have installations of both 3.x and 4.x on my system for testing.
Can that be achieved with homebrew? A simple attempt at brew install r#3.6 just gives me No available formula with the name "r#3.6".
(Aside: the upgrade from 3.6 to 4.0 happened rather sneakily on my system, I did a brew upgrade dvc and that upgraded a few dependencies [Installing dependencies for dvc: c-ares, protobuf, grpc, gcc, openblas, sqlite, python#3.8, numpy, zstd and apache-arrow] and then an avalanche of dependents:
==> Upgrading 42 dependents:
ansible 2.9.6_1 -> 2.9.10, ansible 2.9.6_1 -> 2.9.10, awscli 2.0.7 -> 2.0.28_1,
awscli 2.0.7 -> 2.0.28_1, cython 0.29.10 -> 0.29.20, cassandra 3.11.4 -> 3.11.6_2,
ffmpeg 4.2.2_2 -> 4.3_2, ffmpeg 4.2.2_2 -> 4.3_2, gdal 2.4.4_4 -> 3.1.1_2,
gdal 2.4.4_4 -> 3.1.1_2, gdal 2.4.4_4 -> 3.1.1_2, gdal 2.4.4_4 -> 3.1.1_2,
gdal 2.4.4_4 -> 3.1.1_2, gdal 2.4.4_4 -> 3.1.1_2, glib 2.64.2 -> 2.64.3, glib 2.64.2 -> 2.64.3,
graphviz 2.42.3 -> 2.44.0, graphviz 2.42.3 -> 2.44.0, harfbuzz 2.6.4 -> 2.6.8,
hdf5 1.12.0 -> 1.12.0_1, imagemagick 7.0.10-6_1 -> 7.0.10-23,
imagemagick 7.0.10-6_1 -> 7.0.10-23, ipython 7.13.0 -> 7.16.1, jupyterlab 2.1.0 -> 2.1.5,
libdap 3.20.5 -> 3.20.6, libdap 3.20.5 -> 3.20.6, libheif 1.6.2_1 -> 1.7.0,
libheif 1.6.2_1 -> 1.7.0, maxima 5.43.2 -> 5.44.0, maxima 5.43.2 -> 5.44.0,
netcdf 4.7.4 -> 4.7.4_1, pipenv 2018.11.26_3 -> 2020.6.2, pipenv 2018.11.26_3 -> 2020.6.2,
poppler 0.87.0 -> 0.90.0, poppler 0.87.0 -> 0.90.0, python 3.7.7 -> 3.7.8,
python-yq 2.7.2 -> 2.10.1, qcachegrind 18.04.3_1 -> 19.08.3, r 3.6.3_1 -> 4.0.2_1,
r 3.6.3_1 -> 4.0.2_1, shared-mime-info 1.15 -> 2.0, shared-mime-info 1.15 -> 2.0
which is is why I'm trying to get an installation of R 3.6 back.)

Since R 3.6.3 is not actively maintained in the upstream, homebrew-core did not have a versioned formula for it. There is some hacky way of installing the most recent 3.6.3 version.
$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core # switch to your local homebrew-core folder
$ git reset --hard c3a244c627e # effective reset to the most recent r3.6.3 edition
Updating files: 100% (3680/3680), done.
HEAD is now at c3a244c627e r: update 3.6.3_2 bottle.
$ git checkout -b r-3.6.3 # this would prevent messing up your source tree
Switched to a new branch 'r-3.6.3'
$ brew reinstall r # this would reinstall 3.6.3_2
$ git checkout master # checkout back to source tree
Installation log
==> Downloading https://homebrew.bintray.com/bottles/gcc-9.3.0_1.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/de8319322428721741a0dc41dfdf2eece80e0215a7a4a861e0e206a9bfbca583?response-
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/openblas-0.3.9.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/15116c0a8d1f359f83761de72835021cbad6a814cf7fd53cc93428b522f06dda?response-
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/r-3.6.3_2.mojave.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/c6d4210a241f9466804d5660b467afb6f59d2150e43288b1c66e47387ff43f6e?response-
######################################################################## 100.0%
==> Reinstalling r
==> Installing dependencies for r: gcc and openblas
==> Installing r dependency: gcc
==> Pouring gcc-9.3.0_1.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/gcc/9.3.0_1: 1,463 files, 292MB
==> Installing r dependency: openblas
==> Pouring openblas-0.3.9.mojave.bottle.tar.gz
==> Caveats
openblas is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS in Accelerate.framework.
For compilers to find openblas you may need to set:
export LDFLAGS="-L/usr/local/opt/openblas/lib"
export CPPFLAGS="-I/usr/local/opt/openblas/include"
For pkg-config to find openblas you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/openblas/0.3.9: 23 files, 119.7MB
==> Installing r
==> Pouring r-3.6.3_2.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/r/3.6.3_2: 2,122 files, 58.2MB
==> Caveats
==> openblas
openblas is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS in Accelerate.framework.
For compilers to find openblas you may need to set:
export LDFLAGS="-L/usr/local/opt/openblas/lib"
export CPPFLAGS="-I/usr/local/opt/openblas/include"
For pkg-config to find openblas you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
version check verification
$ r --version
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin18.7.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
legacy formula
Besides you can install thru the hacky way, I also made a legacy formula submission on this. https://github.com/Homebrew/homebrew-core/pull/58063

Note there seems to be no entry for the latest Mac big_sur in r's v3 formula, so #chenrui's method no longer works on new versions of Mac (it says Error: Failed to load formula: r: Invalid bottle tag symbol: Treating r as a cask.)
Solution: do the same as they suggest, but instead of the core repo, use the cask repo, and the revision you want to check out is 6d3bdc6 instead. Updated steps to follow:
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask # cask, not core
git reset --hard 6d3bdc6
git checkout -b r-3.6.3
HOMEBREW_NO_AUTO_UPDATE=1 brew reinstall homebrew/cask/r # Will install v3 from cask (which works on newer Macs), not formula (which is unsupported on newer Macs)
git checkout master
# Finally, since brew won't link this cask automatically:
ln -s /Library/Frameworks/R.framework/Resources/bin/R /usr/local/bin

Related

Update R in anaconda

My first idea was to get R version 4 on my rstudio beside anaconda
My ADD brain then fought getting the newest version of R in my base environment
I have before created new conda environments with different versions of R without a problem
Now I start R in my Ubuntu 18.04.5 and get:
R version 3.5.1
I download the newest version of R (should be 4.0.5) with conda install -c conda-forge r-base
I restart the computer but I am stuck in R version 3.5.1
I do conda update -n base conda and nothing changes
conda config --show-sources
==> /home/notandi/anaconda3/.condarc <==
channels:
- conda-forge
- bioconda
- defaults
==> /home/notandi/.condarc <==
channels:
- bioconda
- defaults
conda info:
active environment : base
active env location : /home/notandi/anaconda3
shell level : 1
user config file : /home/notandi/.condarc populated config files : /home/notandi/anaconda3/.condarc
/home/notandi/.condarc
conda version : 4.10.1
conda-build version : 3.20.2
python version : 3.7.7.final.0
virtual packages : __linux=4.15.0=0
__glibc=2.27=0
__unix=0=0
__archspec=1=x86_64
base environment : /home/notandi/anaconda3 (writable)
conda av data dir : /home/notandi/anaconda3/etc/conda conda av metadata url : https://repo.anaconda.com/pkgs/main
channel URLs : https://conda.anaconda.org/bioconda/linux-64
https://conda.anaconda.org/bioconda/noarch
https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
https://conda.anaconda.org/conda-forge/linux-64
https://conda.anaconda.org/conda-forge/noarch
package cache : /home/notandi/anaconda3/pkgs
/home/notandi/.conda/pkgs
envs directories : /home/notandi/anaconda3/envs
/home/notandi/.conda/envs
platform : linux-64
user-agent : conda/4.10.1 requests/2.25.1 CPython/3.7.7 Linux/4.15.0-143-generic ubuntu/18.04.5 glibc/2.27
UID:GID : 1000:1000
netrc file : None
offline mode : False
What does the Singularity want from me?
The best solution for me is to update the place where Anaconda is looking for the packages. To do that:
Open Anaconda
Go to Environments and select your desired environment
Lets add a new channel to look for updated packages: button Channels --> click Add --> type conda-forge --> enter --> click Update Channels
Lets wait until Anaconda update packages list and look for the R package (now it should show you the last version) and either update it or installed it from crash.

JPEG2000 Losses Read DICOM in Python 3.7

In my Python 3.7, I want to read DICOM. But I face this notification:
NotImplementedError: this transfer syntax JPEG 2000 Image Compression
(Lossless Only), can not be read because Pillow lacks the jpeg 2000
decoder plugin.
I've tried this solution, but anaconda prompt gives me this:
failed
UnsatisfiableError: The following specifications were found to be in
conflict:
- gdcm -> python=3.6 -> python_abi=[build=*_cp36m] -> pypy[version='<0a0']
- python=3.7
Use "conda search --info" to see the dependencies for each
package.
What should I do?
I'm not an expert in conda, but it doesn't look like there are any versions of GDCM available on conda forge for Windows with Python 3.7+, you'll need to stick with 3.6.
If you want to use Pillow with the JPEG2k plugin with conda then you should conda install -c conda-forge openjpeg before installing pillow (see the pydicom installation instructions).

How to use julia's PackageCompiler to build a quick launch environment for PlotStats?

I want to use 'DataFrames,CSV,StatsPlots' packages without waiting time after reboot machine, I'm trying to use PackageCompiler, but the README or help is hard to understand.
using using PackageCompiler
syso, sys = compile_incremental(:DataFrames,:CSV,:StatsPlots)
Well, I'm afraid to destroy the system image, so, at first, I don't use the 'force=true' option. It shows error messages:
...
Resolving package versions...
ERROR: LoadError: Unsatisfiable requirements detected for package WinRPM [c17dfb99]:
WinRPM [c17dfb99] log:
├─possible versions are: [0.3.3, 0.4.0-0.4.3] or uninstalled
├─restricted by compatibility requirements with PackageCompiler [9b87118b] to versions: [0.3.3, 0.4.0-0.4.3]
│ └─PackageCompiler [9b87118b] log:
│ ├─possible versions are: [0.5.0-0.5.1, 0.6.0-0.6.5] or uninstalled
│ └─restricted to versions * by an explicit requirement, leaving only versions [0.5.0-0.5.1, 0.6.0-0.6.5]
├─restricted by compatibility requirements with Compat [34da2185] to versions: 0.4.3 or uninstalled, leaving only versions: 0.4.3
│ └─Compat [34da2185] log:
│ ├─possible versions are: [1.0.0-1.0.1, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.5.0-1.5.1, 2.0.0, 2.1.0, 2.2.0, 3.0.0, 3.1.0, 3.2.0] or uninstalled
│ └─restricted to versions 3.2.0 by an explicit requirement, leaving only versions 3.2.0
└─restricted by compatibility requirements with HTTPClient [0862f596] to versions: uninstalled — no versions left
└─HTTPClient [0862f596] log:
├─possible versions are: 0.2.1 or uninstalled
└─restricted by compatibility requirements with Compat [34da2185] to versions: uninstalled
└─Compat [34da2185] log: see above
It seems workable by PackageCompilerX. At first, the package's version is very sensitive, it require correct version to let everything work.
Here are two of my testing environment for julia 1.3.1
debian: apt -t unstable install julia libjulia-dev
archlinux: pacman -S julia
check Julia's version(PackageCompilerX only work after 1.3.1)
julia> versioninfo()
Julia Version 1.3.1
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: Intel(R) Xeon(R) CPU # 2.20GHz
Add PackageCompilerX and all package which you want to plot to repository
pkg> add https://github.com/KristofferC/PackageCompilerX.jl
pkg> status
Status `~/.julia/environments/v1.3/Project.toml`
...
Copy system's Project.toml to current directory for customize your development environment, use editor(here vim) to remove some package which can't compile or not required.
shell> rm Project.toml
shell> cp ~/.julia/environments/v1.3/Project.toml .
shell> vim Project.toml
activate local package environment
julia> using PackageCompilerX
pkg> activate .
pkg> status # double check all package which you want have installed
Status `~/prj/julia/Project.toml`
[336ed68f] CSV v0.5.22
[a93c6f00] DataFrames v0.20.0
...
generated sybmol array automatically in julia prompt
s=split(read("Project.toml", String),"\n")
pkgs=Symbol[]
for i in s
if (length(i) > 0) && !(i[1] in ['[','#'])
push!(pkgs, Symbol(split(i," ")[1]))
end
end
show pkgs
julia> pkgs
10-element Array{Symbol,1}:
:CSV
:DataFrames
...
compile it and output to "dev.so" by
julia> create_sysimage(pkgs, sysimage_path="dev.so")
exit julia, and re-launch julia by
julia -J dev.so
Benchmark these two launch method and result:
time julia -q -e 'using Plots,UnicodePlots; unicodeplots(); display(plot(sin))'
# result: 35.175s
time julia -J dev.so -q -e 'using Plots,UnicodePlots; unicodeplots(); display(plot(sin))'
# result: 15.2365s

Installing OpenMDAO 2.6.0 Errors

My system right now is running Python 3.5.2 with pip version 19.0.3 and I'm trying to install OpenMDAO using pip. I run the command like it says on the getting started page of the website to install:
pip install openmdao
It begins to runs but then I get the following errors:
error: can't copy 'openmdao/devtools/xdsm_viewer/XDSMjs/build': doesn't exist or not a regular file
Failed building wheel for openmdao"
Any suggestions to fix this?
I am not able to replicate your issue. Are you starting from a clean environment?
Here is my attempt:
~ $ conda create -n O35 python=3.5 numpy scipy --quiet
Solving environment: ...working... done
## Package Plan ##
environment location: /home/swryan/anaconda2/envs/O35
added / updated specs:
- numpy
- python=3.5
- scipy
The following NEW packages will be INSTALLED:
blas: 1.0-mkl
ca-certificates: 2019.1.23-0
certifi: 2018.8.24-py35_1
intel-openmp: 2019.1-144
libedit: 3.1.20181209-hc058e9b_0
libffi: 3.2.1-hd88cf55_4
libgcc-ng: 8.2.0-hdf63c60_1
libgfortran-ng: 7.3.0-hdf63c60_0
libstdcxx-ng: 8.2.0-hdf63c60_1
mkl: 2018.0.3-1
mkl_fft: 1.0.6-py35h7dd41cf_0
mkl_random: 1.0.1-py35h4414c95_1
ncurses: 6.1-he6710b0_1
numpy: 1.15.2-py35h1d66e8a_0
numpy-base: 1.15.2-py35h81de0dd_0
openssl: 1.0.2r-h7b6447c_0
pip: 10.0.1-py35_0
python: 3.5.6-hc3d631a_0
readline: 7.0-h7b6447c_5
scipy: 1.1.0-py35hfa4b5c9_1
setuptools: 40.2.0-py35_0
sqlite: 3.27.2-h7b6447c_0
tk: 8.6.8-hbc83047_0
wheel: 0.31.1-py35_0
xz: 5.2.4-h14c3975_4
zlib: 1.2.11-h7b6447c_3
Proceed ([y]/n)?
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
~ $ conda activate O35
(O35) ~ $ pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl
mkl-random 1.0.1 requires cython, which is not installed.
Installing collected packages: pip
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
Successfully installed pip-19.0.3
(O35) ~ $ pip install openmdao
Collecting openmdao
Collecting pyparsing (from openmdao)
Using cached https://files.pythonhosted.org/packages/de/0a/001be530836743d8be6c2d85069f46fecf84ac6c18c7f5fb8125ee11d854/pyparsing-2.3.1-py2.py3-none-any.whl
Collecting six (from openmdao)
Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting pyDOE2 (from openmdao)
Collecting networkx>=2.0 (from openmdao)
Requirement already satisfied: scipy in ./anaconda2/envs/O35/lib/python3.5/site-packages (from openmdao) (1.1.0)
Requirement already satisfied: numpy in ./anaconda2/envs/O35/lib/python3.5/site-packages (from openmdao) (1.15.2)
Collecting decorator>=4.3.0 (from networkx>=2.0->openmdao)
Using cached https://files.pythonhosted.org/packages/f1/cd/7c8240007e9716b14679bc217a1baefa4432aa30394f7e2ec40a52b1a708/decorator-4.3.2-py2.py3-none-any.whl
Installing collected packages: pyparsing, six, pyDOE2, decorator, networkx, openmdao
Successfully installed decorator-4.3.2 networkx-2.2 openmdao-2.6.0 pyDOE2-1.1.2 pyparsing-2.3.1 six-1.12.0
(O35) ~ $

dyld: Library not loaded: /usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib

When I run R I get:
dyld: Library not loaded: /usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib
Referenced from: /usr/local/Cellar/r/3.5.0_1/lib/libR.dylib
Reason: image not found
Abort trap: 6
Indeed the file is absent:
ls /usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib
ls: cannot access '/usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib': No such file or directory
I'm on macOS 10.13.3 and used homebrew to install R like this:
# Java
brew cask install java
# OpenBLAS (installs gcc and other dependencies)
brew install openblas
# R language for statistical computing
brew install r --with-openblas --with-java
# Install XQuartz, needed for R package "Cairo"
brew cask install xquartz
# Needed for R package "RMySQL"
brew install mariadb-connector-c
# Needed for R packages: udunits2, units, ggforce
brew install udunits
Let's see if the installed version of openblas is 0.2.20:
brew info openblas
openblas: stable 0.3.0 (bottled), HEAD [keg-only]
Optimized BLAS library
https://www.openblas.net/
/usr/local/Cellar/openblas/0.3.0 (22 files, 139MB)
Poured from bottle on 2018-05-31 at 20:42:55
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openblas.rb
==> Dependencies
Required: gcc âś”
==> Options
--with-openmp
Enable parallel computations with OpenMP
--HEAD
Install HEAD version
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS and LAPACK in the Accelerate framework.
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/openblas/lib
CPPFLAGS: -I/usr/local/opt/openblas/include
For pkg-config to find this software you may need to set:
PKG_CONFIG_PATH: /usr/local/opt/openblas/lib/pkgconfig
We have 0.3.0 but R is looking for 0.2.20
To fix this, we can create a symlink from the installed dylib:
ln -s /usr/local/opt/openblas/lib/libopenblas.dylib \
/usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib
It works!
R
R version 3.5.0 (2018-04-23) -- "Joy in Playing"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.4.0 (64-bit)
Another solution is simply to reinstall R:
brew reinstall r
This will relink R against the correct libraries, and you won't have any symlinks that might get orphaned or cause problems later. This won't affect any R packages you have already installed. Also, if you've already installed the most recent version of R with brew and the bottle is still on your computer then you won't have to download the bottle again.
In my case running uninstall and reinstall didn't resolve the issue. Running brew doctor revealed I had unlined kegs including gcc running brew link gcc fixed the issue.
brew upgrade R in most cases will make sure the requirements are installed:
==> Upgrading 1 outdated package:
r 3.5.3 -> 3.6.1
==> Upgrading r
==> Pouring r-3.6.1.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/r/3.6.1: 2,121 files, 56.6MB
Removing: /usr/local/Cellar/r/3.5.3... (2,118 files, 55.8MB)
I had a similar error, first for 'libopenblas' and then for 'libgfortran' on Mac OSX 10.14 using R 3.5.2_2.
Solved it by doing:
brew upgrade R
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/cask and homebrew/bundle).
No changes to formulae.
==> Upgrading 1 outdated package:
r 3.5.2_2 -> 3.6.1
==> Upgrading r
==> Downloading https://homebrew.bintray.com/bottles/r-3.6.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/1e/1ed9fe16ae694fa3b35a7d979853447eb7b8aec1e804019a1bf4aafa299a6696?__gd
######################################################################## 100.0%
==> Pouring r-3.6.1.mojave.bottle.tar.gz
🍺 /usr/local/Cellar/r/3.6.1: 2,121 files, 56.6MB
Removing: /usr/local/Cellar/r/3.4.1_2... (2,113 files, 55.2MB)
Removing: /usr/local/Cellar/r/3.5.1... (2,116 files, 55.6MB)
Removing: /usr/local/Cellar/r/3.5.2_2... (2,119 files, 56.0MB)
R works perfectly after that:
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin18.6.0 (64-bit)

Resources