Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
- store_artifacts:
name: "Store Artifacts: 00install.out"
path: chiimp.Rcheck/00install.out
- run:
name: "Run find_pandoc script"
command: Rscript exec/find_pandoc.R
- run:
name: "Run demo script"
command: bash exec/demo.sh $PWD/demo-files
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# chiimp dev

* Fixed pandoc error with newer RStudio versions (>= 2022.02) by finding
pandoc automatically ([#75])
* Made `load_csv` use custom row names if given ([#74])
* Made installer obey site-wide R configuration if present ([#72])
* Fixed superfluous quotes in report HTML file when rendered with newer pandoc
Expand All @@ -12,6 +14,7 @@
([#63])
* Fixed handling of extra pheatmap arguments in `plot_dist_mat` ([#62])

[#75]: https://github.com/ShawHahnLab/chiimp/pull/75
[#74]: https://github.com/ShawHahnLab/chiimp/pull/74
[#72]: https://github.com/ShawHahnLab/chiimp/pull/72
[#69]: https://github.com/ShawHahnLab/chiimp/pull/69
Expand Down
11 changes: 9 additions & 2 deletions exec/chiimp.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ set rpath=%rpath: "%1"=%
set rpath=%rpath:"=%
set rdir=%rpath%\..\

REM TODO: detect RStudio instead of presuming the path
set RSTUDIO_PANDOC=C:\Program Files\RStudio\bin\pandoc
REM Figure out path to pandoc.
REM Haven't bothered to figure out what combinations of options to for /f are
REM quite right between this command and the one for rpath above. If anyone
REM reading this understands the insanity of Microsoft's syntax here please go
REM ahead and make a pull request to clean this up.
REM Also note that spaces are OK in the Rscript path but not the path to the
REM script; for some reason that makes space-handling for the whole command
REM fail.
for /f "tokens=* usebackq" %%x in (`"%rdir%\Rscript" %dir%\find_pandoc.R`) do set RSTUDIO_PANDOC=%%x

if "%~1"=="" (
echo.To run CHIIMP, drag and drop a configuration file onto this icon.
Expand Down
3 changes: 1 addition & 2 deletions exec/chiimp.command
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ if [[ $# -eq 0 ]]; then
echo "https://shawhahnlab.github.io/chiimp/GUIDE.pdf"
echo
else
which pandoc > /dev/null || export RSTUDIO_PANDOC=/Applications/RStudio.app/Contents/MacOS/pandoc/

if [[ ! "$dir" =~ ^/ ]]; then
rel=$(pwd)
fi
export RSTUDIO_PANDOC=$(Rscript "$rel/$dir/find_pandoc.R")
cd "$cfg_dir"
Rscript "$rel/$dir/chiimp" "$@"
fi
Expand Down
2 changes: 1 addition & 1 deletion exec/chiimp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [[ $# -eq 0 ]]; then
echo "https://shawhahnlab.github.io/chiimp/GUIDE.pdf"
echo
else
which pandoc > /dev/null || export RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc
export RSTUDIO_PANDOC=$(Rscript "$dir/find_pandoc.R")
cd "$cfg_dir"
Rscript "$dir/chiimp" $*
fi
Expand Down
50 changes: 50 additions & 0 deletions exec/find_pandoc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env Rscript

# Figure out the path to the pandoc executable's parent directory. In order of
# priority:
#
# 1. Anything set in RSTUDIO_PANDOC env variable
# 2. Anything found in installed copies of RStudio
# 3. Any other pandoc found on PATH

find_pandoc <- function() {
# If there's already an environment variable defined, we'll just give that.
pandoc_env <- Sys.getenv("RSTUDIO_PANDOC")
if (pandoc_env != "") {
return(pandoc_env)
}

# On Windows this should give something like "c:/", but an empty string
# everywhere else.
prefix <- sub("/.*$", "/", normalizePath(".", winslash = "/"))

# Search for RStudio installations
search_paths <- c(
list.files(list.files(prefix, pattern = "Program Files.*", full.names = TRUE), pattern = "RStudio.*", full.names = TRUE),
list.files("/Applications", pattern = "^RStudio.*.app", full.names = TRUE),
"/usr/lib/rstudio")

execs <- file.path(
strsplit(Sys.getenv("PATH"), .Platform$path.sep)[[1]],
c("pandoc", "pandoc.exe"))
execs <- execs[file.exists(execs)]

# Find files (no dirs) that are named exactly "pandoc" or "pandoc.exe", and
# get the full path to the parent dir of any found
pandoc_dirs_available <- c(
dirname(list.files(search_paths, recursive = TRUE, full.names = TRUE, pattern = "^(pandoc|pandoc\\.exe)$")),
dirname(execs))

# Let rmarkdown package decide which pandoc to use, if that feature is
# available (>=2.2). It will also implicitly accept a pandoc executable found
# on the PATH. If that function's not available we'll just pick a pandoc.
# https://stackoverflow.com/a/24692264
pandoc_dir <- if ("find_pandoc" %in% getNamespaceExports("rmarkdown")) {
rmarkdown::find_pandoc(dir = pandoc_dirs_available)$dir
} else {
pandoc_dirs_available[1]
}
return(pandoc_dir)
}

cat(find_pandoc(), "\n", sep = "")