Skip to content

knitreg doesn't work if knitting directory differs from file directory #197

Description

@svraka

Consider the following R Markdown file in somewhere/project/paper/report.Rmd

---
title: This is in a subdirectory
output: github_document
---

```{r setup}
library(texreg)
knitr::opts_chunk$set(error = TRUE)
m <- lm(mpg ~ wt, data = mtcars)
getwd()
```

```{r knitreg}
knitreg(m)
```

```{r htmlreg}
htmlreg(m)
```

Rendering it from somewhere/project with rmarkdown::render("paper/report.Rmd", knit_root_dir = getwd()) result in errors for knitreg but not for htmlreg

This is in a subdirectory
================

``` r
library(texreg)
knitr::opts_chunk$set(error = TRUE)
m <- lm(mpg ~ wt, data = mtcars)
getwd()
```

    ## [1] "/somewhere/project"

``` r
knitreg(m)
```

    ## Warning in readLines(con, warn = FALSE): cannot open file 'report.Rmd': No such file or directory

    ## Error in readLines(con, warn = FALSE): cannot open the connection

``` r
htmlreg(m)
```

    ## <table class="texreg" style="margin: 10px auto;border-collapse: collapse;border-spacing: 0px;caption-side: bottom;color: #000000;border-top: 2px solid #000000;">
    ## <caption>Statistical models</caption>
    ##
    ## ... Rest of outout omitted
    ##
    ## </table>

I came across this issue while rendering a targets pipeline with tar_render(), where knitting in the file's directory is not practical.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions