On Mon, Oct 6, 2014 at 7:03 PM, Henrik Bengtsson <h...@biostat.ucsf.edu> wrote: > On Mon, Oct 6, 2014 at 6:48 PM, Henrik Bengtsson <h...@biostat.ucsf.edu> > wrote: >> On Mon, Oct 6, 2014 at 5:33 PM, Martin Morgan <mtmor...@fhcrc.org> wrote: >>> On 10/06/2014 04:52 PM, Henrik Bengtsson wrote: >>>> >>>> Maybe you could use >>>> >>>> \RequirePackage{Bioconductor} >>>> >>>> and then set the TEXINPUTS environment variable via Sys.setenv(). >>>> Internally tools::texi2dvi() is used that that "listens to" TEXINPUTS. >>> >>> >>> Thanks; I think that would require 'us' to run texi2dvi (otherwise the >>> environment variable isn't seen by texi2dvi) and that sounds like writing a >>> Sweave driver, or worse. latex() could be modified to be passed a flag or >>> path indicating a TEXINPUTS directory where bioconductor.sty could be found, >>> but that doesn't sound like a robust strategy (e.g., because the >>> specially-installed sty file becomes out of sync with the version in the >>> package). Hopefully there is a simpler solution. >> >> I haven't tried, but it's possible that if you do >> Sys.setenv(TEXINPUTS=...) when the BiocStyle is loaded/attached that >> it will stick/survive until the vignette is built. > > It works to set environment variables in either .onLoad() or > .onAttach(). I verified with: > > .onLoad <- function(libname, pkgname) { > Sys.setenv(FOO="hello") > } > > .onAttach <- function(libname, pkgname) { > Sys.setenv(BAR="world") > } > > that both environment variables 'FOO' and 'BAR' are available to the > vignette itself and have their values set as expected. I've tried > with vignette engines knitr::Rmd and R.rsp::rsp and in both cases the > build and installed vignettes show FOO=hello and BAR=world. > > Given that this works, I would be surprised if you cannot set > TEXINPUTS such that texi2dvi() et al. won't see it.
See attached latex.R (adopted from https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/BiocStyle/R/latex.R). A diff -C 3 (also attached) is: *** latex_org.R 2014-10-08 11:34:15.949845400 -0700 --- latex.R 2014-10-08 11:33:31.932327700 -0700 *************** *** 1,15 **** latex <- function(..., width=90, short.fignames=FALSE, fig.path, error=FALSE, use.unsrturl=TRUE) { options(..., width=width) ! cat(sprintf("\\RequirePackage{%s}\n\n", ! sub(".sty$", "", .bioconductor.sty))) if (use.unsrturl) { ! bst <- file.path(system.file(package="BiocStyle", "resources", ! "latex"), "unsrturl") ! cat(sprintf("\\AtBeginDocument{\\bibliographystyle{%s}}\n", bst)) } setPrefix = function(x) { --- 1,43 ---- + unique_path <- + function(path, sep=.Platform$path.sep, collapse=sep) + { + n <- length(path) + has_tail_sep <- (substring(path[n], nchar(path[n])) == sep) + path <- unlist(strsplit(path, split=sep, fixed=TRUE)) + path <- unique(path) + path <- path[nchar(path) > 0L] + path <- path[sapply(path, function(.) file_test("-d", .))] + if (has_tail_sep) path <- c(path, "") + paste(path, collapse=collapse) + } + + texinputs <- + function(new=NULL, name="TEXINPUTS") + { + current <- Sys.getenv(name) + if (length(new) > 0L) { + new <- normalizePath(new) + args <- list(unique_path(c(new, current))) + names(args) <-name + do.call(Sys.setenv, args) + current <- Sys.getenv(name) + } + invisible(current) + } + latex <- function(..., width=90, short.fignames=FALSE, fig.path, error=FALSE, use.unsrturl=TRUE) { options(..., width=width) ! ! texinputs(new=dirname(.bioconductor.sty)) ! cat("\\RequirePackage{Bioconductor}\n\n") if (use.unsrturl) { ! bst_path <- system.file(package="BiocStyle", "resources", "latex") ! texinputs(new=bst_path, name="BSTINPUTS") ! cat("\\AtBeginDocument{\\bibliographystyle{unsrturl}}\n") } setPrefix = function(x) { You may want to make those function local to latex(). I haven't verified it works (won't have time), but I bet a beer that it will work. /Henrik > > /Henrik > >> >> /Henrik >> >>> >>> Martin >>> >>> >>>> >>>> Just FYI: I use this trick in >>>> https://github.com/HenrikBengtsson/R.rsp/blob/master/R/compileLaTeX.R >>>> to set/fix/update TEXINPUTS temporarily, but for somewhat different >>>> reasons. There you also see take extra precautions to drop duplicates >>>> etc. >>>> >>>> /Henrik >>>> >>>> On Mon, Oct 6, 2014 at 3:21 PM, Martin Morgan <mtmor...@fhcrc.org> wrote: >>>>> >>>>> On 10/6/2014 2:44 PM, James W. MacDonald wrote: >>>>>> >>>>>> >>>>>> Hi Steffen, >>>>>> >>>>>> It looks like you are running R as an administrator, rather than as a >>>>>> regular user (or you are on something really old like XP). By default R >>>>>> should try to create a user-level library directory in your Documents >>>>>> folder. It is probably not such a good idea to run R as administrator if >>>>>> you are on a more modern version of Windows. >>>>>> >>>>>> Note that system.file (which BiocStyle::latex() calls to find the >>>>>> package >>>>>> path) will in the case of base packages use .Library to construct the >>>>>> path: >>>>>> >>>>>>> system.file() >>>>>> >>>>>> >>>>>> [1] "C:/PROGRA~1/R/R-31~1.0/library/base" >>>>>> >>>>>> Which being an 8.1 path, will work for MikTex. But if I run as an >>>>> >>>>> >>>>> >>>>> It would be great for BiocStyle to return a functional path under all >>>>> circumstances. >>>>> >>>>> I'm not sure that MikTex handles ~ in paths? or at least not the way >>>>> BiocStyle currently uses this, as >>>>> >>>>> >>>>> \RequirePackage{C:/PROGRA~1/R/R-31~1.0/library/BiocStyle/sty/Bioconductor} >>>>> >>>>> When I try to mock this up it looks like the ~ are being processed as >>>>> latex >>>>> -- there is a latex file not found error with the ~ replaced by >>>>> \unhbox\voidb@x \penalty \@m \{}. >>>>> >>>>> I thought there might be some hints with the Sweave sty file use by all >>>>> vignettes. This is found with >>>>> >>>>> styfile <- file.path(R.home("share"), "texmf", "tex", "latex", >>>>> "Sweave") >>>>> if (.Platform$OS.type == "windows") >>>>> styfile <- chartr("\\", "/", styfile) >>>>> if (length(grep(" ", styfile))) >>>>> warning(gettextf("path to %s contains spaces,\n", >>>>> sQuote(styfile)), >>>>> gettext("this may cause problems when running >>>>> LaTeX"), >>>>> domain = NA) >>>>> >>>>> but R.home() (eventually find.package()) uses .Library for the special >>>>> case >>>>> when the path to a single package from the base distribution is being >>>>> sought >>>>> >>>>>> find.package("stats") >>>>> >>>>> [1] "C:/PROGRA~1/R/R-31~1.1/library/stats" >>>>>> >>>>>> find.package(c("stats", "stats"))[1] >>>>> >>>>> [1] "C:/Program Files/R/R-3.1.1/library/stats" >>>>> >>>>> So I'm not sure how to get at a working path to Bioconductor.sty in the >>>>> face >>>>> of spaces in the installed path name (the warning hints that R has >>>>> similar >>>>> problems). >>>>> >>>>> >>>>>> administrator and put BiocStyle in my Program Files library, I get >>>>>> >>>>>>> latex() >>>>>> >>>>>> >>>>>> \RequirePackage{C:/Program >>>>>> Files/R/R-3.1.0/library/BiocStyle/sty/Bioconductor} >>>>>> >>>>>> \AtBeginDocument{\bibliographystyle{C:/Program >>>>>> Files/R/R-3.1.0/library/BiocStyle/sty/unsrturl}} >>>>>> >>>>>> Which of course will fail. So the best option is to stop running R as an >>>>>> administrator, and install packages in your Documents folder in a path >>>>>> with >>>>>> no spaces. >>>>>> >>>>>> Best, >>>>>> >>>>>> Jim >>>>>> >>>>>> >>>>>> >>>>>> On Mon, Oct 6, 2014 at 4:34 PM, Neumann, Steffen <sneum...@ipb-halle.de> >>>>>> wrote: >>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> sometimes I am forced to R CMD check packages on windows, >>>>>>> and my problem is that both the system-wide library and >>>>>>> the personal library with BiocStyle contain spaces, so that >>>>>>> BiocStyle::latex() results in: >>>>>>> \RequirePackage{C:/Program >>>>>>> Files/R/R-3.1.0/library/BiocStyle/sty/Bioconductor} >>>>>>> >>>>>>> which causes MiKTeX to fail with >>>>>>> ! LaTeX Error: File >>>>>>> `C:/ProgramFiles/R/R-3.1.0/library/BiocStyle/sty/Bioconductor.sty' not >>>>>>> found. >>>>>>> (This is with BiocStyles-1.3.15) >>>>>>> >>>>>>> What is the recommended solution here ? Installing R to a non-standard >>>>>>> location ? >>>>>>> Use texlive instead of miktex (does that make a difference ?) Or >>>>>>> something >>>>>>> else ? >>>>>>> >>>>>>> Yours, >>>>>>> Steffen >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> Bioc-devel@r-project.org mailing list >>>>>>> https://stat.ethz.ch/mailman/listinfo/bioc-devel >>>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Dr. Martin Morgan, PhD >>>>> Fred Hutchinson Cancer Research Center >>>>> 1100 Fairview Ave. N. >>>>> PO Box 19024 Seattle, WA 98109 >>>>> >>>>> >>>>> _______________________________________________ >>>>> Bioc-devel@r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/bioc-devel >>> >>> >>> >>> -- >>> Computational Biology / Fred Hutchinson Cancer Research Center >>> 1100 Fairview Ave. N. >>> PO Box 19024 Seattle, WA 98109 >>> >>> Location: Arnold Building M1 B861 >>> Phone: (206) 667-2793
*** latex_org.R 2014-10-08 11:34:15.949845400 -0700 --- latex.R 2014-10-08 11:33:31.932327700 -0700 *************** *** 1,15 **** latex <- function(..., width=90, short.fignames=FALSE, fig.path, error=FALSE, use.unsrturl=TRUE) { options(..., width=width) ! cat(sprintf("\\RequirePackage{%s}\n\n", ! sub(".sty$", "", .bioconductor.sty))) if (use.unsrturl) { ! bst <- file.path(system.file(package="BiocStyle", "resources", ! "latex"), "unsrturl") ! cat(sprintf("\\AtBeginDocument{\\bibliographystyle{%s}}\n", bst)) } setPrefix = function(x) { --- 1,43 ---- + unique_path <- + function(path, sep=.Platform$path.sep, collapse=sep) + { + n <- length(path) + has_tail_sep <- (substring(path[n], nchar(path[n])) == sep) + path <- unlist(strsplit(path, split=sep, fixed=TRUE)) + path <- unique(path) + path <- path[nchar(path) > 0L] + path <- path[sapply(path, function(.) file_test("-d", .))] + if (has_tail_sep) path <- c(path, "") + paste(path, collapse=collapse) + } + + texinputs <- + function(new=NULL, name="TEXINPUTS") + { + current <- Sys.getenv(name) + if (length(new) > 0L) { + new <- normalizePath(new) + args <- list(unique_path(c(new, current))) + names(args) <-name + do.call(Sys.setenv, args) + current <- Sys.getenv(name) + } + invisible(current) + } + latex <- function(..., width=90, short.fignames=FALSE, fig.path, error=FALSE, use.unsrturl=TRUE) { options(..., width=width) ! ! texinputs(new=dirname(.bioconductor.sty)) ! cat("\\RequirePackage{Bioconductor}\n\n") if (use.unsrturl) { ! bst_path <- system.file(package="BiocStyle", "resources", "latex") ! texinputs(new=bst_path, name="BSTINPUTS") ! cat("\\AtBeginDocument{\\bibliographystyle{unsrturl}}\n") } setPrefix = function(x) {
_______________________________________________ Bioc-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/bioc-devel