RstanCompileR Mac Catalina

IN R
package brms requires stan
command brm excecutiion TRIEs to install Rstan - and then hangs
xannot instal rstan from packages in R studio
complicated net instructions don’t work

format_code(like_this, if_applicable)

If you need to use math formula, use Latex syntax:

Y \sim N(\mu, \sigma)

Don’t forget to attach tags (top right of this form) for application area/class of models or other general subject areas your topic touches on.

Welcome to the community!

So you want to install brms, and brms needs Stan? Well,

  1. Install R
  2. Install RStudio
  3. Install a tool chain (compiler etc.)
  4. Install rstan
  5. Install brms

No. 3 depends very much on your operating system, i.e., Windows, OS X, Linux. Can you give us more information?

1 Like

Is the problem. All the rest works fine
Machine: Bac lapbook
Operating system: Catalina 10.15.6.This is problem
went to https://www.cnet.com/how-to/install-command-line-developer-tools-in-os-x/
wanted option 3 but didn’t work
Alos tried macostool
downloaded package BUT
Catalina won’t open it because it mgiht be malicious!
Securtiy seetings do not show tthis so I can’t cahnge permissions
Goinground in circles.
Needs help fro MAC expert who knows catalina
thanks for help

Hi

I use 10.15.6,

  1. Install Xcode
  2. Open Terminal and type: xcode-select --install

Then try again to install rstan

Thanks I did this. xcode-select —ixcode-select --install
See below 1 for terminal, 2 for attempt to install rstan -again
Also on stan forums

xcode-select --install

1. Terminal interaction

The default interactive shell is now zsh.
To update your account to use zsh, please run chsh -s /bin/zsh.
For more details, please visit https://support.apple.com/kb/HT208050.
Dianas-MacBook-Pro:~ kornbrot18$ xcode-select --install
xcode-select: note: install requested for command line developer tools
Dianas-MacBook-Pro:~ kornbrot18$
Dianas-MacBook-Pro:~ kornbrot18$ xcode-select --install
xcode-select: note: install requested for command line developer tools
Dianas-MacBook-Pro:~ kornbrot18$
Dianas-MacBook-Pro:~ kornbrot18$
Dianas-MacBook-Pro:~ kornbrot18$ xcode-select --install
xcode-select: error: command line tools are already installed, use “Software Update” to install updates
Dianas-MacBook-Pro:~ kornbrot18$
Dianas-MacBook-Pro:~ kornbrot18$ Software Updat
-bash: Software: command not found
Dianas-MacBook-Pro:~ kornbrot18$ Software Update
-bash: Software: command not found
Dianas-MacBook-Pro:~ kornbrot18$ xcode-select: error: command line tools are already installed, use “Software Update”
-bash: xcode-select:: command not found
Dianas-MacBook-Pro:~ kornbrot18$
2. Install rstan interaction
Massive output ending with

Thanks I did this. xcode-select —ixcode-select --install

See below 1 for terminal interacrtion, 2 for attempt to install rstan -again
So failed and still need help

Also on stan forums

On 11 Sep 2020, at 13:47, Richard Torkar via The Stan Forums mc_stan@discoursemail.com wrote:

xcode-select —ixcode-select --install

1. Terminal interaction

The default interactive shell is now zsh.

To update your account to use zsh, please run chsh -s /bin/zsh.

For more details, please visit Use zsh as the default shell on your Mac - Apple Support.

Dianas-MacBook-Pro:~ kornbrot18$ xcode-select --install

xcode-select: note: install requested for command line developer tools

Dianas-MacBook-Pro:~ kornbrot18$

Dianas-MacBook-Pro:~ kornbrot18$ xcode-select --install

xcode-select: note: install requested for command line developer tools

Dianas-MacBook-Pro:~ kornbrot18$

Dianas-MacBook-Pro:~ kornbrot18$

Dianas-MacBook-Pro:~ kornbrot18$ xcode-select --install

xcode-select: error: command line tools are already installed, use “Software Update” to install updates

Dianas-MacBook-Pro:~ kornbrot18$

Dianas-MacBook-Pro:~ kornbrot18$ Software Updat

-bash: Software: command not found

Dianas-MacBook-Pro:~ kornbrot18$ Software Update

-bash: Software: command not found

Dianas-MacBook-Pro:~ kornbrot18$ xcode-select: error: command line tools are already installed, use “Software Update”

-bash: xcode-select:: command not found

Dianas-MacBook-Pro:~ kornbrot18$

2. Install rstan interaction

Massive output ending with

_______

clang: error: no such file or directory: ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan/lib//libStanServices.a’

make: *** [rstan.so] Error 1

ERROR: compilation failed for package ‘rstan’

  • removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan’

  • restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan’

Warning in install.packages :

installation of package ‘rstan’ had non-zero exit status

The downloaded source packages are in

‘/private/var/folders/yp/2vlb80dd3slg22j_y6f83rmh0000gn/T/RtmpZ6NFf6/downloaded_packages’

testhat(bayeslgt)

Error in testhat(bayeslgt) : could not find function “testhat”

bayesrawX <-brm(proptn ~ wiithin+ (1|pno), data=kexa)

Error in brm(proptn ~ wiithin + (1 | pno), data = kexa) :

could not find function “brm”


Hi,

something is clearly still wrong and it can’t find the compiler it seems. I just install Xcode and then I open the terminal and write:

xcode-select --install

Since I already have the compiler installed it says,

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

If I type clang++ in the terminal I get this:

clang: error: no input files

so I can clearly execute clang++. What do you get when you type clang++ in the terminal?

That’s what I get

Can you type this in the terminal and paste the text?

cat ~/.R/Makevars
cat ~/.Rprofile
cat ~/.Renviron

And I see that you actually have clang in your path, so it wasn’t the problem as I assumed… :)

And once you’ve done that try this in R:

remove.packages("rstan")

if (file.exists(".RData")) file.remove(".RData")

install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)

and if the above doesn’t work I would recommend you follow this and use the installer and then follow the instructions:

1 Like

and restart R before you try please

1 Like

brm is now functioning with 4 chains. Takes a long time but that’s OK
It sends me off to https://resourced.prometheanworld.com/state-of-technology-2020-early-access/?persona=teacher&utm_source=pardot&utm_medium=email&utm_campaign=202009-UKI-DigitalMarketing-StateofTechnology2020&utm_content=Matched&utm_term=EM1
Which takes the biscuit for muddled instruction - cleverly giving the ’simplest’ solution last!
After my pushing return several time stan got compiled and stuff happened
Still sorting out the error messages

Eternally grateful

Best
Diana

I can get brm answer but please help, have following dialogue

I did that and everything that had been working stopped working
Guess I need to go back to terminal and start again

Working now -thanks

1 Like

R rstan compilation problems MAC Catalina: Summary Solution
Apple OS needs modifying.

  1. close R/Rstudio
  2. launch terminal.app. usually in utilities folder, in applicattions folder
  3. update whartever it tells you to update, then type the following
    xcode-select --install
    cat ~/.R/Makevars
    cat ~/.Rprofile
    cat ~/.Renviron
    do not worry abut any messages abut stuff already installed
    4. Relaunch Rstudio and type**
    remove.packages(“rstan”)

if (file.exists(".RData")) file.remove(".RData")

install.packages(“rstan”, repos = “https://cloud.r-project.org/”, dependencies = TRUE)
if you get red message about installing from source, type "no"
5. Install the packages you need that require compilation of rstan
tick the required functions in the packages pane
Now ready to usee R functions needing rstan
6. Example Bayes with function brm for binomial probability using raw proportiion
#install brms, tick brms in packagees pane
bayesrawX <-brm(proptn ~ wiithin+ (1|pno), data=kexa) #repeated measure on raw data
#gives red error message
Compiling Stan program…
sh: clang++ -mmacosx-version-min=10.13: command not found
#Ignore message and WAIT.
Compiling rstan takes time, eventually get brm execution (black)
SAMPLING FOR MODEL ‘e52d31baa3a07a5714e7fe5823f2997d’ NOW (CHAIN 1).
Chain 1:
Chain 1: Gradient evaluation took 5.4e-05 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.54 seconds.
Chain 1: Adjust your expectations accordingly!

Chain 4: Elapsed Time: 1.10458 seconds (Warm-up)
Chain 4: 0.376411 seconds (Sampling)
Chain 4: 1.48099 seconds (Total)
Chain 4:
There may also be a red warning message of form
Warning messages:
1: In system2(CXX, args = ARGS) : error in running command
2: In file.remove(c(unprocessed, processed)) :
cannot remove file ‘/var/folders/yp/2vlb80dd3slg22j_y6f83rmh0000gn/T//RtmpjMKouj/file129746fd45f52.stan’, reason ‘No such file or directory’
#No idea what that means. *BUT brm has been excuted
#Check object bayesrawX has been created by typing
bayesrawX
May be followed by other commnads to extract useful info
Can get results in object as follows
brmX <- emmeans(bayesrawX, ~wiithin, data =kexa)
brmX
pairs(brmX)
anova(bayeslrawX)
summary(bayesrawX) #more detail than just 'bayesrawX"
Zillion thanks to Richard Torka and Rstan forum that sorted this out for me

2 Likes