I have updated my bash to bash version 4.4.0 on mac osx. However, as explained in this question, I cannot update the bash version under bin/bash but just install a parallel shell under /usr/local/bin/bash
how can I point knitr to this shell? engine.path seems to get ignored:
```{r, engine='bash', engine.path='/usr/local/bin/bash'}
which bash
```
gives
/bin/bash
update
# Kevin: yes you are right, echo $BASH gives /usr/local/bin/bash
BUT:
from knitr
```{bash, engine.path='/usr/local/bin/bash'}
which bash
echo $BASH
bash --version
```
gives
/bin/bash
/usr/local/bin/bash
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)
Copyright (C) 2007 Free Software Foundation, Inc.
while the same from the command line gives
edit 2
after re-reading the answer of #Kevin, this works
```{r, engine = "bash", engine.path = "/usr/local/bin/bash"}
export PATH="/usr/local/bin:$PATH"
bash --version
```
GNU bash, version 4.4.0(1)-release (x86_64-apple-darwin15.6.0)
What does echo $BASH print? It's possible that your PATH has /usr/bin before /usr/local/bin, or even /usr/local/bin is not on the PATH.
For example, I see:
indicating that engine.path is indeed being respected.
Related
I try to setup my zsh-completions. I also use oh-my-zsh .
A lot of shell commands provide a some_command completion zsh
and they often suggest sourcing it directly in .zshrc like so:
source <(kubeone completion zsh)
source <(tilt completion zsh)
source <(civo completion zsh)
I can't get it working. Only when I output the command into a file echo "$(kubeone completion zsh)" > ~/.dotfiles/completions/_kubeone.
(That ~/.dotfiles/completions/-path is in my fpath):
fpath=(/usr/local/share/zsh-completions $fpath)
fpath=(~/.dotfiles/completions $fpath)
But that approach is not that neat. I wanna make the use of adding
source $(my_command completion zsh) to my .zsh_rc file.
Interestingly SOME commands are working with that approach: like: source <(kompose completion zsh) but source <(kubeone completion zsh) wont???
Here is an excerpt from my ~/.zshrc:
#!/bin/sh
[ -f ~/.dotfiles/fubectl.source ] && source ~/.dotfiles/fubectl.source
export ZSH_THEME="powerlevel10k/powerlevel10k"
export DOTFILES=$HOME/.dotfiles
export ZSH=$DOTFILES/oh-my-zsh
BUNDLED_COMMANDS=(rubocop)
UNBUNDLED_COMMANDS=(berks foreman mailcatcher rails ruby spin rubocop)
plugins=(zsh-completions zsh-autosuggestions docker fzf bundler brew cask capistrano codeclimate coffee dotenv gem git github grunt helm heroku history iterm2 minikube node redis-cli redis-cli rails rake rake-fast ruby rbenv textmate macos pod zeus terraform)
source $ZSH/oh-my-zsh.sh
complete -o nospace -C /usr/local/bin/terraform terraform
# load autocomplete
fpath=(/usr/local/share/zsh-completions $fpath)
fpath=(~/.dotfiles/completions $fpath)
autoload -U compinit && compinit
source <(kompose completion zsh) # WORKS
source <(kubeone completion zsh) # DONT WORK
(kompose a→tab WORKS)
kubeone a→tab returns only my folder structure
❯ kubeone completion zsh
Application\ Support/ MAMP/ VirtualBox\ VMs/ oh-my-zsh
Applications/ Movies/ Wine\ Files/ output.json
Coding/ Music/ builds/
...
..
.
but should return:
❯ kubeone apply
apply -- Reconcile the cluster
completion -- Generates completion scripts for bash and zsh
config -- Commands for working with the KubeOneCluster configuration manifests
document -- Generates documentation
help -- Help about any command
install -- Install Kubernetes
...
..
.
What I tried so far:
after opening terminal rm ~/.zcompdump*, then tried command, then reopened terminal and tried command again.
autoload -Uz compinit && compinit -i with different arguments
I think there is some misconfiguration or maybe a brew formula is disturbing?
Here is the complete output of my brew list command, as well my complete .zshrc file: https://gist.github.com/exocode/79c9acfad9828b73d05d2abfa39f1724
I need to issue unix commands from an R session. I'm on Windows R2 2012 server using RStudio 1.1.383 and R 3.4.3.
The shell() function looks to be the right one for me but when I specify the path to my bash shell (from Git for Windows install) the command fails with error code 127.
shell_path <- "C:\\Program Files\\Git\\git-bash.exe"
shell("ls -a", shell = shell_path)
## running command 'C:\Program Files\Git\git-bash.exe /c ls -a' had status 127'ls -a' execution failed with error code 127
Pretty sure my shell path is correct:
What am I doing wrong?
EDIT: for clarity I would like to pass any number of UNIX commands, I am just using ls -a for an example.
EDIT:
After some playing about 2018-03-09:
shell(cmd = "ls -a", shell = '"C:/Program Files/Git/bin/bash.exe"', intern = TRUE, flag = "-c")
The correct location of my bash.exe was at .../bin/bash.exe. This uses shell with intern = TRUE to return the output as an R object. Note the use of single quote marks around the shell path.
EDIT: 2018-03-09 21:40:46 UT
In RStudio we can also call bash using knitr and setting chunk options:
library(knitr)
```{bash my_bash_chunk, engine.path="C:\\Program Files\\Git\\bin\\bash.exe"}
# Using a call to unix shell
ls -a
```
Two things stand out here. Bash will return exit code 127 if a command is not found; you should try running the fully qualified command name.
I also see that your shell is being run with a /c flag. According to the documentation, the flag argument specifies "the switch to run a command under the shell" and it defaults to /c, but "if the shell is bash or tcsh or sh the default is changed to '-c'." Obviously this isn't happening for git-bash.exe.
Try these changes out:
shell_path <- "C:\\Program Files\\Git\\git-bash.exe"
shell("/bin/ls -a", shell = shell_path, flag = "-c")
Not on Windows, so can't be sure this will work.
Perhaps you need to use shQuote?
shell( paste("ls -a ", shQuote( shell_path) ) )
(Untested. I'm not on Windows. But do read ?shQuote))
If you just want to do ls -a, you can use the below commands:
shell("'ls -a'", shell="C:\\Git\\bin\\sh.exe")
#or
shell('C:\\Git\\bin\\sh.exe -c "ls -a"')
Let us know if the space in "Program Files" is causing problems.
And if you require login before you can call your command,
shell('C:\\Git\\bin\\sh.exe --login -c "ls -a"')
But if you are looking at performing git commands from R, the git2r by ropensci might suit your needs.
I am struggling with writing a script that would somehow scrape the https://www.rstudio.com/products/rstudio/download/ for the number of the latest RStudio version, download it and install it.
Since I am an R programmer, I started to write an R script using rvest package. I managed to scrape the download link for the RStudio server, but I still cannot get the RStudio itself.
Here is the R code for getting a download link for the 64bit RStudio-server for Ubuntu.
if(!require('stringr')) install.packages('stringr', Ncpus=8, repos='http://cran.us.r-project.org')
if(!require('rvest')) install.packages('rvest', Ncpus=8, repos='http://cran.us.r-project.org')
xpath<-'//code[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]'
url<-'https://www.rstudio.com/products/rstudio/download-server/'
thepage<-xml2::read_html(url)
the_links_html <- rvest::html_nodes(thepage,xpath=xpath)
the_links <- rvest::html_text(the_links_html)
the_link <- the_links[stringr::str_detect(the_links, '-amd64\\\\.deb')]
the_r_uri<-stringr::str_match(the_link, 'https://.*$')
cat(the_r_uri)
Unfortunately, the RStudio desktop download page has completely different layout, and I the same approach doesn't work here.
Can someone help me with this? I can't believe, that all the data scientist in the world manually upgrade their RStudio!
There is an even simpler version of the script, that reads the version of the RStudio-server. Bash version:
RSTUDIO_LATEST=$(wget --no-check-certificate -qO- https://s3.amazonaws.com/rstudio-server/current.ver)
or R version:
scan('https://s3.amazonaws.com/rstudio-server/current.ver', what = character(0))
But the version of the RStudio-desktop still eludes me.
It seems that you can get the latest stable version number from the url http://download1.rstudio.org/current.ver and it is more up to date (for some unknown reason), at least at the time of writing this answer.
$ curl -s http://download1.rstudio.org/current.ver
1.1.447
$ curl -s https://www.rstudio.org/links/check_for_update?version=1.0.0 | grep -oEi 'update-version=([0-9]+\.[0-9]+\.[0-9]+)' | awk -F= '{print $2}'
1.1.423
Found that here: https://github.com/yutannihilation/ansible-playbook-r/blob/master/tasks/install-rstudio-server.yml
If you query RStudio's check_for_update with a version string you'll get back the update version and the URL of where to get it from:
https://www.rstudio.org/links/check_for_update?version=1.0.0
update-version=1.0.153&update-url=https%3A%2F%2Fwww.rstudio.com%2Fproducts%2Frstudio%2Fdownload%2F&update-message=RStudio%201.0.153%20is%20now%20available%20%28you%27re%20using%201.0.0%29&update-urgent=0
See here:
https://github.com/rstudio/rstudio/blob/54cd3abcfc58837b433464c793fe9b03a87f0bb4/src/cpp/session/modules/SessionUpdates.R
If you really want to scrape it from the download page then I'd get the href of the <a> in the first <td> of the first <table> of class "downloads", and then parse out the three dot-separated numbers between "RStudio-" and ".exe". RStudio release versions over all platforms so getting it from the Windows download should be sufficient.
> url = "https://www.rstudio.com/products/rstudio/download/"
> thepage<-xml2::read_html(url)
> html_node(thepage, ".downloads td a") %>% html_attr("href")
[1] "https://download1.rstudio.org/RStudio-1.0.153.exe"
There's a nearly-solution here:
https://hub.docker.com/r/rocker/rstudio-daily/~/dockerfile/
In this script, which scrapes for the latest builds:
https://raw.githubusercontent.com/rocker-org/rstudio-daily/master/latest.R
You'll want to modify that script to be more strict about what it accepts, i.e. I would want this one rstudio-server-1.1.355-amd64.deb and not the stretch variant.
(But you can modify it to target the kind of build you want anyway, this is the daily builds, RStudio Server for Ubuntu.)
If anyone is interested, here is my ultimate RServer-desktop-on-Ubuntu update script. It installs RStudio-desktop 64bit and then, if Fira Console font is available, applies a patch from https://github.com/tonsky/FiraCode/wiki/RStudio-instructions for the RStudio, so the ligatures start working.
#!/bin/bash
if dpkg -s rstudio >/dev/null 2>/dev/null; then
ver=$(apt show rstudio | grep Version)
pattern='^Version: ([0-9.]+)\s*$'
if [[ $ver =~ $pattern ]]; then
ourversion=${BASH_REMATCH[1]}
netversion=$(Rscript -e 'cat(stringr::str_match(scan("https://www.rstudio.org/links/check_for_update?version=1.0.0", what = character(0), quiet=TRUE), "^[^=]+=([^\\&]+)\\&.*")[[2]])')
if [[ $ourversion != $netversion ]]; then
RSTUDIO_URI=$(Rscript /tmp/get_rstudio_uri.R)
fi
tee /tmp/get_rstudio_uri.R <<EOF
if(!require('rvest')) install.packages('rvest', repos='http://cran.us.r-project.org')
xpath='.downloads:nth-child(2) tr:nth-child(5) a'
url = "https://www.rstudio.com/products/rstudio/download/"
thepage<-xml2::read_html(url)
cat(html_node(thepage, xpath) %>% html_attr("href"))
EOF
RSTUDIO_URI=$(Rscript /tmp/get_rstudio_uri.R)
wget -c --output-document /tmp/rstudio.deb $RSTUDIO_URI
sudo dpkg -i /tmp/rstudio.deb
rm /tmp/rstudio.deb
rm /tmp/get_rstudio_uri.R
if fc-list |grep -q FiraCode; then
if !grep -q "text-rendering:" /usr/lib/rstudio/www/index.htm; then
sudo sed -i '/<head>/a<style>*{text-rendering: optimizeLegibility;}<\/style>' /usr/lib/rstudio/www/index.htm
fi
fi
fi
fi
I've just installed Arch and LxQt, when I lookup things on the ArchWiki it shows weird characters (black/white circles, squares...) at the place where the quoted texts are. I did uncomment "en_US.UTF-8" and "zh_TW.UTF-8" and ran localegen.
Any pointer ? I am an Arch beginner.
Regards,
Jonathan MONDAUT
Please check if you have ttf-dejavu installed in your computer. If not, you can install it with the following command.
pacman -S ttf-dejavu
You can check with the following in your Terminal.
if (pacman -Q ttf-dejavu >/dev/null) ; then echo "ttf-dejavu installed"; fi
I've created a simple example showing the problem I currently have.
I have a R-markdown file, named example.Rmd, containing the following code
```{r}
plot(rnorm(10000))
```
and a Makefile file with the following content
all : example01.html example02.html
example01.html : example.Rmd
Rscript -e "library(knitr); knit2html(input='example.Rmd', output='example01.html')"
example02.html : example.Rmd
Rscript -e "library(knitr); knit2html(input='example.Rmd', output='example02.html')"
If I run the Makefile file sequentially
make
there is no problem.
If I run the makefile in parallel
make -j 2
the chunks generated by knit2html function overlap and both html files contains the same image.
Any suggestion? I've been searching for a solution but I've found nothing.
Using the idea of Karl, I've written a possible solution.
all : example01.html example02.html
example01.html : example.Rmd
mkdir -p dir_$#
Rscript -e 'library(knitr); opts_knit$$set(base.dir = "dir_$#"); knit2html(input="example.Rmd", output="dir_$#/$#")'
mv dir_$#/$# .
rm -r dir_$#
example02.html : example.Rmd
mkdir -p dir_$#
Rscript -e 'library(knitr); opts_knit$$set(base.dir = "dir_$#"); knit2html(input="example.Rmd", output="dir_$#/$#")'
mv dir_$#/$# .
rm -r dir_$#
There are two modifications respect to initial code.
As Karl commented, I've included the line opts_knit$set(base.dir= "dir_example0?.html") in such a way the figure folder is create in that path.
I've swap " and ' symbol in Rscript -e command as commented here
Parallel execution
make -j 2
works fine.