montilab / hypeR

An R Package for Geneset Enrichment Workflows
https://montilab.github.io/hypeR-docs/
GNU General Public License v3.0
76 stars 11 forks source link

hyp_to_rmd(file_path = ) has problems with relative paths #23

Closed jdrnevich closed 4 years ago

jdrnevich commented 4 years ago

I came across a weird issue when trying to use hyp_to_rmd - the file_path argument can take a plain file name or an absolute path, but not a relative path:

> library(hypeR)
> library(tidyverse)
#deleted for space 
> load(file.path(system.file("extdat", package="hyperworkshop"), "limma.rda"))
> genesets <- msigdb_gsets("Homo sapiens", "C2", "CP:KEGG")
> signature <- signature <- limma %>%
+   dplyr::filter(t > 0 & fdr < 0.001) %>%
+   magrittr::use_series(symbol)
> hyp_obj <- hypeR(signature, genesets, test="hypergeometric", background=50000, fdr=0.01, plotting=TRUE)
> hyp_to_rmd(hyp_obj,
+            file_path="hypeR.rmd")
processing file: hypeR.rmd
# deleted for space
Output created: hypeR.rmd.html

> getwd()
[1] "C:/Users/jenny/"
> dir.create("test")
> hyp_to_rmd(hyp_obj,
+            file_path="test/hypeR.rmd")
Error: The directory 'test' does not not exist.

> hyp_to_rmd(hyp_obj,
+            file_path="C:/Users/jenny/test/hypeR.rmd")
processing file: hypeR.rmd
# deleted for space
Output created: hypeR.rmd.html

I did some debugging and the problem occurs in rmarkdown::render(). It wants output directory separate from the file name and does weird things like calling setwd(dirname(abs_path(input))) so you can't put relative paths in hyp_to_rmd(file_path = ). Easiest thing to do would be to add a warning in the help file, which also should say that file_path needs to end in .rmd or it won't be rendered properly:

> dir.create("test2")
> hyp_to_rmd(hyp_obj,
+            file_path="C:/Users/jenny/test2/hypeR")
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS hypeR.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc552854ab6fdb.html --email-obfuscation none --self-contained --standalone --section-divs --table-of-contents --toc-depth 1 --variable toc_float=1 --variable toc_selectors=h1 --variable toc_collapsed=1 --variable toc_smooth_scroll=1 --variable toc_print=1 --template "C:\Users\jenny\R\win-library\4.0\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:united" --include-in-header "C:\Users\jenny\AppData\Local\Temp\Rtmpyuarak\rmarkdown-str55283b06aa5.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --lua-filter "C:/Users/jenny/R/win-library/4.0/rmarkdown/rmd/lua/pagebreak.lua" --lua-filter "C:/Users/jenny/R/win-library/4.0/rmarkdown/rmd/lua/latex-div.lua" --variable code_folding=hide --variable code_menu=1 

Output created: test2/hypeR.html
#open test2/hypeR.html and see it's not rendered correctly

One final request: could you strip off the .rmd when creating the html file name? I am used to having hypeR.rmd and the rendered hypeR.html and hypeR.rmd.html is just clunky. Thanks!

anfederico commented 4 years ago

Thank you for the suggestion, both relative paths and extension replacement have been fixed.