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

Improvements to etable #473

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Improvements to etable #473

wants to merge 8 commits into from

Conversation

kylebutts
Copy link
Contributor

Hi Laurent,

This PR has a set of commits to (potentially) improve etable. Here's the set of changes:

  1. div.class is an option for setFixest_etable to match markdown.

  2. etable(..., file = path) fails when path has a directory that doesn't exist. This PR checks for this and creates the directory if needed.

  3. Fix a sort of nefarious bug with export. Say you have etable(..., export = path) where path is a relative directory, the directory does not exist, and markdown = FALSE. The function check_set_path will return the relative path back. However, building the png sets the working directory to tempdir(), so moving the png to path fails.

  4. Allowing for named exports How do you name the PNG file that etable exports? #451

    To do this, the file name is extracted if it exists (and with the fix to 3) and used as png_name.

  5. The controversial change involves markdown processing. I can remove this one if you don't agree.

    • Rmarkdown and quarto (both using knitr) saves plots in knitr::fig_path() (usually X_files/figures-html/). Putting the etable pngs in here gives the benefit of allowing self_contained to process them.

    • Quarto/knitr has the option output.dir which lets your execution working directory differ from where the output is created. You can access this with knitr::opts_knit$get("output.dir"). This means with this option, the images produced by etable won't be in the correct location of the html document.

      For example, if I have a .Rmd in a subfolder (e.g. ./vignettes/) but I want it use the main folder (./) as the working directory, etable will use ./etable/images/ instead of ./vignettes/etable/images.

      By using these two functions, I think etable much better ties in with quarto/rmarkdown. I've faced this problem with my own day-to-day use of qmd, so it's not just a random edge case (or maybe I'm the edge case).

- In `build_tex_png`, `*.png` is detected, use that as `png_name` and then remove from `export`
- Needed to move `export_path` creation below to ensure this works
This one is a bit complicated as it happens only when `export` is used, the image is built in `tempdir()`, *and* the directory does not exist.

`check_set_path` returns either relative or absolute path:
- If `etable` has to make the directory, then relative path.
- If it doesn't then, then absolute path.

This creates problems when you `setwd(tempdir())` to build the image because `file.copy` copies into the tempdir when using a relative path
- `knitr::fig_path('.png')` creates a file in the Rmarkdown output directory. This is really useful since it can be processed with `self_contained`, for example
- Additinally, knitr has `output.dir` option to, so this outputs into the correct output dir correctly. For example when using `quarto` with `execute-dir`, the output dir and the execute dir can differ.
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.

None yet

1 participant