-
-
Save noamross/7a096fb5378974cfa8fe4fd7d5cc46d0 to your computer and use it in GitHub Desktop.
A bash shell script that can be used to turn the current directory into an RStudio project, opening the project in RStudio after creating it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: mkproj [projectname] | |
# projectname defaults to name of current directory | |
template="Version: 1.0 | |
RestoreWorkspace: No | |
SaveWorkspace: No | |
AlwaysSaveHistory: Yes | |
EnableCodeIndexing: Yes | |
UseSpacesForTab: Yes | |
NumSpacesForTab: 2 | |
Encoding: UTF-8 | |
RnwWeave: knitr | |
LaTeX: XeLaTeX | |
AutoAppendNewline: Yes | |
StripTrailingWhitespace: Yes | |
QuitChildProcessesOnExit: Yes | |
" | |
gtemplate=".Rproj.user | |
.Rhistory | |
.RData | |
.Ruserdata | |
" | |
wd=$(basename "`pwd`") | |
if [ -z $1 ]; then | |
projectname=$wd | |
else | |
projectname=$1 | |
fi | |
count=`ls -1 *.Rproj 2>/dev/null | wc -l` | |
if [ $count == 0 ] | |
then | |
echo "${template}" > "${projectname}.Rproj" | |
fi | |
if [ ! -e .gitignore ] | |
then | |
echo "${gtemplate}" > .gitignore | |
fi | |
# Open the newly created project in RStudio: | |
open "${projectname}.Rproj" |
I had to change the last line to rstudio "${projectname}.Rproj"
or I got an error:
Couldn't get a file descriptor referring to the console
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now updated to avoid overwriting files