Skip to content

Conversation

@gadenbuie
Copy link
Member

When an htmlDependency() doesn't have any files, copyDependencyToDir() will still create an empty directory, as in the reprex below. This PR fixes this behavior by cleaning up the target directory when the dependency doesn't have any source files.

We still temporarily create the target directory and update the dependencies $src$file value, though, because rmarkdown will eventually call makeDependencyRelative() and we need $src$file to be a child of the document's basedir or an error is thrown.

---
output: 
  html_document:
    self_contained: no
---

```{r echo=FALSE}
# create empty temp dir
tmpdir <- tempfile()
dir.create(tmpdir)

# add an htmldependency from that tempdir
htmltools::tagList(
  htmltools::htmlDependency(
    name = "empty",
    version = "9.9.9",
    src = tmpdir,
    head = "<script>alert('boo')</script>",
    all_files = FALSE
  )
)
```

@cpsievert cpsievert self-requested a review June 28, 2021 21:24
@cpsievert cpsievert requested a review from schloerke June 28, 2021 21:25
@MoLi7
Copy link

MoLi7 commented Sep 24, 2021

I suppose this PR should fix the mysterious empty directories created after knitting a xaringan and xaringanExtra powered presentation, as described in this StackOverflow question.

Could someone merge this PR to implement @gadenbuie's proposal? Thank you!

@SNAnalyst
Copy link

I don't know it this adds any additional information, but I have found that this problem occurs when I use

xaringanextra::use_clipboard()

(regardless of whether I add htmltools::tagList() after this. So, just xaringanextra::use_clipboard() creates this behavior by itself already.

Co-authored-by: Barret Schloerke <barret@rstudio.com>
@gadenbuie
Copy link
Member Author

@cpsievert I made the change requested by @schloerke, this should be good to go now!

@cpsievert
Copy link
Collaborator

@gadenbuie thanks! Please also add a NEWS item and then I'll merge

gadenbuie and others added 3 commits November 12, 2021 14:03
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
@cpsievert
Copy link
Collaborator

@schloerke
Copy link
Collaborator

@cpsievert I have no clue. 😞

It is extremely odd. It is tied to r-lib/actions/setup-r-dependencies in the line: pak::pkg_deps("local::.", dependencies = TRUE) when making the dependencies file for caching.

Why it is odd is that every other linux job works. I also busted the cache by incrementing the cache number, still no improvement. Also removed `extra-packages to be installed afterwards, still no improvement.

NEWS.md Outdated

* Closed #225: Added `tagInsertChildren()` to be able to insert child tag objects at a particular location. (#224)

* `copyDependencyToDir()` no longer creates empty directories for dependencies that do not have any files. (@gadenbuie, #276)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gadenbuie would you mind rebasing/merging with main so this gets put in the right place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpsievert cpsievert merged commit e472321 into rstudio:main Nov 18, 2021
@gadenbuie gadenbuie deleted the no-empty-dirs branch July 22, 2022 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants