Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Rmd files in subdirectories and common lib_dir #146

Closed
gaborcsardi opened this issue Jun 28, 2014 · 13 comments
Closed

Multiple Rmd files in subdirectories and common lib_dir #146

gaborcsardi opened this issue Jun 28, 2014 · 13 comments

Comments

@gaborcsardi
Copy link

I have a bunch of Rmd files, spread in some subdirectories, e.g.

aaa/bbb/one.Rmd
aaa/ccc/two.Rmd
...

I want to convert them to HTML, and use a common lib_dir for all of them. The problem is, that if I do

render("aaa/bbb/one.Rmd", NULL, 
       output_options=list(self_contained=FALSE, lib_dir="lib"))

then the lib directory (and more importantly the the references in the generated HTML accordingly) end up in aaa/bbb/lib, which is obviously not what I want.

If I try

setwd("aaa/bbb/")
render("one.Rmd", NULL, output_options=list(self_contained=FALSE, lib_dir="../../lib"))

then I get

Error in relativeTo(basepath, dir) : 
  The path /private/tmp/lib/jquery-1.11.0 does not appear to be a descendant of /private/tmp/aaa/bbb/

Is there a way to create a common lib_dir for these files, and still get the links in the HTML files right?

@andreasio
Copy link

FYI: I went to stackoverflorw with this issue. No answer yet though.

@gaborcsardi
Copy link
Author

One workaround is to create a (symbolic) link for each lib directory output, that points to the real lib directory. The files are still written many times, of course.

@jjallaire
Copy link
Member

The current design assumes a single root directory for documents that want to share a lib_dir. It would be pretty involved to reverse this assumption, so I'd recommend you do something based on symbolic links for now.

@gaborcsardi
Copy link
Author

In the example above, the files are in a common root directory, aaa, and the problem is that lib_dir is not created relative to the common root directory, but relative to the Rmd file.

So it seems that in addition to a common root directory, you need to have all Rmd files in the same directory. Maybe this is what you meant by common root directory.

@jjallaire
Copy link
Member

Yes, that's exactly what I meant.

On Thu, Jul 10, 2014 at 12:50 PM, Gabor Csardi [email protected]
wrote:

In the example above, the files are in a common root directory, aaa,
and the problem is that lib_dir is not created relative to the common
root directory, but relative to the Rmd file.

So it seems that in addition to a common root directory, you need to have
all Rmd files in the same directory. Maybe this is what you meant by common
root directory
.


Reply to this email directly or view it on GitHub
#146 (comment).

@sjackman
Copy link

sjackman commented Nov 4, 2014

👍

@sanjmeh
Copy link

sanjmeh commented Sep 27, 2019

This is a strange restriction.

If I have understood it correct, the lib_dir is expected to be in the same directory as output_dir argument of rmarkdown::render(). This is a big limitation as it forces all the output html files to be saved in the same parent directory where the .Rmd is present. If we want to use the same .Rmd to generate a separate bunch of html files (based on the argument output_dir), we cannot share the same lib_dir. I have 50+ html files generated in every pass, and cannot abandon the subdirectory structure. Do we have a solution to this?

@jonathan-g
Copy link
Contributor

I have the same issue.

I organize my reveal.js slides for a semester in a directory structure:

semester:
    lecture_lib (common material: css, js, etc.)
        assets (custom css themes, custom js, etc.)
        revealjs
        font-awesome
    slides
        class_01
            assets (per-class assets)
                images (images to include)
                videos (video files)
                fig (figures generated by RMarkdown)
        class_02
            assets (per-class assets)
                images (images to include)
                videos (video files)
                fig (figures generated by RMarkdown)
        c;lass_03
            assets (per-class assets)
                images (images to include)
                videos (video files)
                fig (figures generated by RMarkdown)
        ...

This lets me keep a consistent structure for each lecture.

This worked fine with RMarkdown for several years until Pandoc 2.9, when modifications to html_dependencies() broke my structure because RMarkdown insists on creating a file header-attrs.js and I am not given an option of specifying a path to a static version of header-attrs.js.

If I use pandoc 2.7.x, RMarkdown works fine with my directory structures, but if I use any later version of Pandoc I get the same error message about relativeTo().

@cderv
Copy link
Collaborator

cderv commented Jul 7, 2020

@jonathan-g , this is a pretty old issue (2014).
Can you open a new one (linking to this one if you think this is related) with a reproducible example (would be ideal) ?

The fact that something broke with new pandoc make me thing there is something to fix.

Thank you !

@jonathan-g
Copy link
Contributor

Sure.

@sjackman
Copy link

sjackman commented Jul 8, 2020

Could you please post a link to the new issue here?

@jonathan-g
Copy link
Contributor

I just submitted a new issue #1859. I took some time to investigate this more carefully and to write up the new issue carefully before submitting it. I think a small PR can enhance rmarkdown to support this kind of non-standard directory structure (see the fork at https://github.com/jonathan-g/rmarkdown/tree/minimal-tree-fix).

@github-actions
Copy link

github-actions bot commented Jan 5, 2021

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants