Error in markdown when I try to knit ggplot2 output in PDF

I was asked to set up an environment for a skill assessment. AND the file they provided contains a chunk like this:

ggplot(data=subset(dd, DX %in% "CN" & !
aes(x=M, y=ADAS11, group=RID, colour=factor(RID)) +

which leads to an error message like below:

Unescaped left brace in regex is passed through in regex; marked by <-- HERE in m//setup{ <-- HERE [}1{]}_files/figure-latex/test_ggplot-1.pdf/ at /usr/local/bin/tlmgr line 1844.
Error in grep(paste0("/", x[j], ""), l) : invalid regular expression '/setup{[}1{]}_files/figure-latex/test_ggplot-1.pdf', reason 'Invalid contents of {}'
Calls: ... system2_quiet -> on_error -> parse_packages -> grep
In addition: Warning message:
In grep(paste0("/", x[j], "$"), l) :
TRE pattern compilation error 'Invalid contents of {}'
Warning: Package longtable Warning: Column widths have changed
Warning: (longtable) in table 1 on input line 152.
Warning: LaTeX Warning: File `setup{[}1{]}_files/figure-latex/test_ggplot-1.pdf' not found on input line 168.
Execution halted

What should I do to solve this problem ?

I have tried obvious debugging tricks like updating the packages. It did not work.

Assuming that M and ADAS11 are continuous and RID is discrete and that the same subset of DD is plot-able in an ide session, the reason lies in the toolchain being used for rendering to pdf. If our version is the same, the trouble comes here in tlmgr

       │ File: snip
   1   │ sub search_pkg_desc {
   2   │   my ($tlp, $what, $inword) = @_;
   3   │   my $pkg = $tlp->name;
   4   │   my $t = "$pkg\n";
   5   │   $t = $t . $tlp->shortdesc . "\n" if (defined($tlp->shortdesc));
   6   │   $t = $t . $tlp->longdesc . "\n" if (defined($tlp->longdesc));
   7   │   $t = $t . $tlp->cataloguedata->{'topics'} . "\n" if (defined($tlp->cataloguedata->{'topics'}));
   8   │   my $pat = $what;
   9   │   $pat = '\W' . $what . '\W' if ($inword);
  10   │   my $matched = "";
  11   │   if ($t =~ m/$pat/i) {
  12   │     my $shortdesc = $tlp->shortdesc || "";
  13   │     $matched .= "$pkg - $shortdesc";
  14   │   }
  15   │   return $matched;
  16   │ }

Since this has to do with TeX, the $pkg being dealt with is not an R package but a LaTeX one, it means that during compilation, an attempt was made to pass an argument to the tlmgr that was malformed. Because we know that markdown can render ggplot to pdf (put this in a chunk in a new markdown document default template to be rendered as pdf)

mtcars |> ggplot(aes(mpg,drat)) + geom_line()

The problem might lie in tlmgr, in which case you can try using {tinytex}.

1 Like

Can you share some Rmd source for this ? I believe something lies in the code chunks options or other Rmd content ? or even the filename

Hi cderv, you are right. I have found where the problem is. It has nothing to do with tlmgr. The errors occur because the file name of the markdown contains brackets "", so deleting those brackets in the filename solved the problem.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.