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

knitr .Rnw errors result in infinite loop of compilation #2487

Closed
matthewberryman opened this issue Jan 20, 2021 · 12 comments
Closed

knitr .Rnw errors result in infinite loop of compilation #2487

matthewberryman opened this issue Jan 20, 2021 · 12 comments
Labels
enhancement Issue suggests an enhancement question Issue represents a question

Comments

@matthewberryman
Copy link

matthewberryman commented Jan 20, 2021

Preliminary questions [Required]

Disable all the other extensions except for LaTeX Workshop, restart VS Code, and check that you still see this issue. [Required]

You still see this issue?: Yes

Make sure to visit the wiki FAQ before filling an issue.

You visited the wiki?: Yes

If your issue is with compiling a document (not having to do with finding the root file of a project), check first that you can compile manually.

You can compile a TeX document manually?:
I can compile from Rnw > tex.
The second step of latexmk on the tex produces an expected error.

Describe the bug [Required]

A clear and concise description of what the bug is.

To Reproduce

  1. Start with a working document e.g.
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{hyperref}
\title{example title}
\author{Dr Matthew J. Berryman}
\begin{document}
\maketitle

\section{knitr example}

stray

\end{document}
  1. Change to a document with an error, e.g.
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{hyperref}
\title{example title}
\author{Dr Matthew J. Berryman}
\begin{document}
\maketitle

\section{knitr example}

stray {

\end{document}

Expected behaviour

I would expect the error to be logged, and not for LaTeX Workshop to go into an infinite loop of recompilation.

Logs [Required]

[12:17:41] Initializing LaTeX Workshop.
[12:17:41] Extension root: /Users/matthew/.vscode/extensions/james-yu.latex-workshop-8.15.0
[12:17:41] Creating PDF file watcher.
[12:17:41] Creating LaTeX Workshop http and websocket server.
[12:17:41] LaTeX Workshop initialized.
[12:17:41] Current workspace folders: ["file:///Users/matthew/code/CBB/mfxlm-report"]
[12:17:41] Current workspaceRootDir: /Users/matthew/code/CBB/mfxlm-report
[12:17:41] Found root file from active editor: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:41] Root file changed: from undefined to /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:41] Start to find all dependencies.
[12:17:41] Root file languageId: rsweave
[12:17:41] Instantiating a new file watcher for /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:41] Creating Bib file watcher.
[12:17:41] Parsing a file and its subfiles: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:41] Parse fls file.
[12:17:41] Fls file found: /Users/matthew/code/CBB/mfxlm-report/example.fls
[12:17:41] Parsing a file and its subfiles: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:41] Parse fls file.
[12:17:41] Fls file found: /Users/matthew/code/CBB/mfxlm-report/example.fls
[12:17:41] Parse aux file: /Users/matthew/code/CBB/mfxlm-report/example.aux
[12:17:41] Parse aux file: /Users/matthew/code/CBB/mfxlm-report/example.aux
[12:17:41] Server created on 127.0.0.1:56711
[12:17:41] Added to file watcher: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:41] Added to file watcher: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:41] Added to file watcher: /Users/matthew/code/CBB/mfxlm-report/knitr.sty
[12:17:41] LaTeX Workshop version: 8.15.0
[12:17:41] Snippet data loaded.
[12:17:41] Cannot parse a TeX file: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:41] Fall back to regex-based completion.
[12:17:41] Cannot parse a TeX file: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:41] Fall back to regex-based completion.
[12:17:45] File watcher - file changed: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:45] Parsing a file and its subfiles: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:45] Parse fls file.
[12:17:45] Fls file found: /Users/matthew/code/CBB/mfxlm-report/example.fls
[12:17:45] Parse aux file: /Users/matthew/code/CBB/mfxlm-report/example.aux
[12:17:45] Auto build started detecting the change of a file: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:45] BUILD command invoked.
[12:17:45] The document of the active editor: file:///Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:45] The languageId of the document: rsweave
[12:17:45] Building root file: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:45] Build root file /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:45] Recipe step 1: Rscript, -e,knitr::opts_knit$set(concordance = TRUE); knitr::knit('example.Rnw')
[12:17:45] Recipe step env: {}
[12:17:45] cwd: /Users/matthew/code/CBB/mfxlm-report
[12:17:45] LaTeX build process spawned. PID: 52935.
[12:17:45] A step in recipe finished. PID: 52935.
[12:17:45] Recipe step 2: latexmk, -synctex=1,-interaction=nonstopmode,-file-line-error,-pdf,-outdir=/Users/matthew/code/CBB/mfxlm-report,/Users/matthew/code/CBB/mfxlm-report/example
[12:17:45] Recipe step env: {}
[12:17:45] cwd: /Users/matthew/code/CBB/mfxlm-report
[12:17:45] LaTeX build process spawned. PID: 52947.
[12:17:45] File watcher - file changed: /Users/matthew/code/CBB/mfxlm-report/knitr.sty
[12:17:45] Auto Build Run is temporarily disabled during a second.
[12:17:45] File watcher - file changed: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:45] Parsing a file and its subfiles: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:45] Parse fls file.
[12:17:45] Fls file found: /Users/matthew/code/CBB/mfxlm-report/example.fls
[12:17:45] Parse aux file: /Users/matthew/code/CBB/mfxlm-report/example.aux
[12:17:45] Auto Build Run is temporarily disabled during a second.
[12:17:46] LaTeX log parsed with 0 messages.
[12:17:46] Recipe of length 2 finished. PID: 52947.
[12:17:46] Successfully built /Users/matthew/code/CBB/mfxlm-report/example.Rnw.
[12:17:46] No PDF viewer connected for /Users/matthew/code/CBB/mfxlm-report/example.pdf
[12:17:46] Parse fls file.
[12:17:46] Fls file found: /Users/matthew/code/CBB/mfxlm-report/example.fls
[12:17:46] Parse aux file: /Users/matthew/code/CBB/mfxlm-report/example.aux
[12:17:50] File watcher - file changed: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:50] Parsing a file and its subfiles: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:50] Parse fls file.
[12:17:50] Fls file found: /Users/matthew/code/CBB/mfxlm-report/example.fls
[12:17:50] Parse aux file: /Users/matthew/code/CBB/mfxlm-report/example.aux
[12:17:50] Auto build started detecting the change of a file: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:50] BUILD command invoked.
[12:17:50] The document of the active editor: file:///Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:50] The languageId of the document: rsweave
[12:17:50] Building root file: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:50] Build root file /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:50] Cannot parse a TeX file: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:50] Fall back to regex-based completion.
[12:17:50] Recipe step 1: Rscript, -e,knitr::opts_knit$set(concordance = TRUE); knitr::knit('example.Rnw')
[12:17:50] Recipe step env: {}
[12:17:50] cwd: /Users/matthew/code/CBB/mfxlm-report
[12:17:50] LaTeX build process spawned. PID: 52963.
[12:17:50] A step in recipe finished. PID: 52963.
[12:17:50] Recipe step 2: latexmk, -synctex=1,-interaction=nonstopmode,-file-line-error,-pdf,-outdir=/Users/matthew/code/CBB/mfxlm-report,/Users/matthew/code/CBB/mfxlm-report/example
[12:17:50] Recipe step env: {}
[12:17:50] cwd: /Users/matthew/code/CBB/mfxlm-report
[12:17:50] LaTeX build process spawned. PID: 52975.
[12:17:50] File watcher - file changed: /Users/matthew/code/CBB/mfxlm-report/knitr.sty
[12:17:50] Auto Build Run is temporarily disabled during a second.
[12:17:50] File watcher - file changed: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:50] Parsing a file and its subfiles: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:50] Parse fls file.
[12:17:50] Fls file found: /Users/matthew/code/CBB/mfxlm-report/example.fls
[12:17:50] Parse aux file: /Users/matthew/code/CBB/mfxlm-report/example.aux
[12:17:50] Auto Build Run is temporarily disabled during a second.
[12:17:50] Cannot parse a TeX file: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:50] Fall back to regex-based completion.
[12:17:51] LaTeX log parsed with 1 messages.
[12:17:51] Recipe returns with error: 12/null. PID: 52975. message: Latexmk: This is Latexmk, John Collins, 26 Dec. 2019, version: 4.67.
Rule 'pdflatex': File changes, etc:
   Changed files, or newly in use since previous run(s):
      '/Users/matthew/code/CBB/mfxlm-report/example.tex'
      'example.tex'
------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'pdflatex  -synctex=1 -interaction=nonstopmode -file-line-error -recorder -output-directory="/Users/matthew/code/CBB/mfxlm-report"  "/Users/matthew/code/CBB/mfxlm-report/example.tex"'
------------
Latexmk: Log file says output to 'example.pdf'
Collected error summary (may duplicate other messages):
  pdflatex: Command for 'pdflatex' gave return code 1
      Refer to '/Users/matthew/code/CBB/mfxlm-report/example.log' for details
Latexmk: Use the -f option to force complete processing,
 unless error was exceeding maximum runs, or warnings treated as errors.
.
[12:17:51] The environment variable $PATH: /usr/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion Tech Preview.app/Contents/Public:/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Apple/usr/bin:/Users/matthew/bin:/Users/matthew/esp/xtensa-esp32-elf/bin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin
[12:17:51] The environment variable $SHELL: /usr/local/bin/zsh
[12:17:51] Cleaning auxiliary files and retrying build after toolchain error.
[12:17:51] File cleaned: /Users/matthew/code/CBB/mfxlm-report/example.aux
[12:17:51] File cleaned: /Users/matthew/code/CBB/mfxlm-report/example.fls
[12:17:51] File cleaned: /Users/matthew/code/CBB/mfxlm-report/pdflatex52799.fls
[12:17:51] File cleaned: /Users/matthew/code/CBB/mfxlm-report/example.log
[12:17:51] File cleaned: /Users/matthew/code/CBB/mfxlm-report/example.fdb_latexmk
[12:17:51] File cleaned: /Users/matthew/code/CBB/mfxlm-report/example.out
[12:17:51] Recipe step 1: Rscript, -e,knitr::opts_knit$set(concordance = TRUE); knitr::knit('example.Rnw')
[12:17:51] Recipe step env: {}
[12:17:51] cwd: /Users/matthew/code/CBB/mfxlm-report
[12:17:51] LaTeX build process spawned. PID: 52978.
[12:17:51] A step in recipe finished. PID: 52978.
[12:17:51] Recipe step 2: latexmk, -synctex=1,-interaction=nonstopmode,-file-line-error,-pdf,-outdir=/Users/matthew/code/CBB/mfxlm-report,/Users/matthew/code/CBB/mfxlm-report/example
[12:17:51] Recipe step env: {}
[12:17:51] cwd: /Users/matthew/code/CBB/mfxlm-report
[12:17:51] LaTeX build process spawned. PID: 52991.
[12:17:51] File watcher - file changed: /Users/matthew/code/CBB/mfxlm-report/knitr.sty
[12:17:51] Auto build started detecting the change of a file: /Users/matthew/code/CBB/mfxlm-report/knitr.sty
[12:17:51] BUILD command invoked.
[12:17:51] The document of the active editor: file:///Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:51] The languageId of the document: rsweave
[12:17:51] Building root file: /Users/matthew/code/CBB/mfxlm-report/example.Rnw
[12:17:51] File watcher - file changed: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:51] Parsing a file and its subfiles: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:51] Parse fls file.
[12:17:51] Cannot find fls file: /Users/matthew/code/CBB/mfxlm-report/example.fls
[12:17:51] Auto Build Run is temporarily disabled during a second.
[12:17:51] Cannot parse a TeX file: /Users/matthew/code/CBB/mfxlm-report/example.tex
[12:17:51] Fall back to regex-based completion.
[12:17:52] LaTeX log parsed with 2 messages.
[12:17:52] Recipe returns with error: 12/null. PID: 52991. message: Latexmk: This is Latexmk, John Collins, 26 Dec. 2019, version: 4.67.
Rule 'pdflatex': The following rules & subrules became out-of-date:
      'pdflatex'
------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'pdflatex  -synctex=1 -interaction=nonstopmode -file-line-error -recorder -output-directory="/Users/matthew/code/CBB/mfxlm-report"  "/Users/matthew/code/CBB/mfxlm-report/example.tex"'
------------
Latexmk: References changed.
Latexmk: Log file says output to 'example.pdf'
Collected error summary (may duplicate other messages):
  pdflatex: Command for 'pdflatex' gave return code 1
      Refer to '/Users/matthew/code/CBB/mfxlm-report/example.log' for details
Latexmk: Use the -f option to force complete processing,
 unless error was exceeding maximum runs, or warnings treated as errors.
.
[12:17:52] The environment variable $PATH: /usr/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion Tech Preview.app/Contents/Public:/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Apple/usr/bin:/Users/matthew/bin:/Users/matthew/esp/xtensa-esp32-elf/bin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin

(starts to repeat after that point due to bug)

LaTeX Workshop Output [Required]

Cannot access due to bug.

Developer Tools Console [Required]

Keeps repeating this:

Recipe terminated with error.
onDidChangeNotification @ notificationsAlerts.ts:36
(anonymous) @ breadcrumbsModel.ts:294
fire @ event.ts:525
addNotification @ notifications.ts:171
notify @ notificationService.ts:68
(anonymous) @ mainThreadLogService.ts:16
_showMessage @ mainThreadLogService.ts:16
$showMessage @ mainThreadLogService.ts:16
_doInvokeHandler @ rpcProtocol.ts:396
_invokeHandler @ rpcProtocol.ts:330
_receiveRequest @ rpcProtocol.ts:269
_receiveOneMessage @ rpcProtocol.ts:208
(anonymous) @ rpcProtocol.ts:90
fire @ event.ts:525
fire @ ipc.net.ts:449
_receiveMessage @ ipc.net.ts:785
(anonymous) @ ipc.net.ts:642
fire @ event.ts:525
acceptChunk @ ipc.net.ts:191
(anonymous) @ ipc.net.ts:191
t @ ipc.net.ts:925
emit @ events.js:223
addChunk @ _stream_readable.js:309
readableAddChunk @ _stream_readable.js:290
Readable.push @ _stream_readable.js:224
onStreamRead @ internal/stream_base_commons.js:181

Screenshots

Screen.Recording.2021-01-20.at.12.30.30.pm.mp4

Desktop [Required]

  • OS: macOS 11
  • architecture: Intel x64
  • VS Code version: 1.52.1
  • Extension version: 8.15.0
  • TeX distribution version: MacTeX-2020

Additional questions

Are you using VSCodium?

No

Are you using LaTeX Workshop with VS Code Remote?

No

Additional context

@tamuratak
Copy link
Contributor

tamuratak commented Jan 20, 2021

Please add knitr.sty to latex-workshop.latex.watch.files.ignore

See https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-workshoplatexwatchfilesignore

@tamuratak tamuratak added question Issue represents a question enhancement Issue suggests an enhancement labels Jan 20, 2021
@matthewberryman
Copy link
Author

Thanks, that was the source of the issue. I would suggest this be added as a default ignored file, then.

@jlelong
Copy link
Collaborator

jlelong commented Jan 20, 2021

I cannot reproduce the issue and I am a bit puzzled by the file knitr.sty being modified during compilation.
With your example, I do not have any file knitr.sty listed in example.fls. I want to understand all the details of this before possibly adding knitr.sty to latex-workshop.latex.watch.files.ignore.

@tamuratak
Copy link
Contributor

tamuratak commented Jan 20, 2021

See

If the option self.contained is false, LaTeX headers are written to the file knitr.sty.

@matthewberryman
Copy link
Author

matthewberryman commented Jan 20, 2021

In ~/.Rprofile I had:

library('knitr')
opts_knit$set(self.contained=FALSE)

based on https://support.rstudio.com/hc/en-us/articles/200486298-Working-with-Multiple-Rnw-Files
since I am working with multiple .Rnw files.

However, after removing that, I can then trigger another infinite loop when I save this document with an error (misplaced ampersand)

\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{hyperref}
\title{example title}
\author{Dr Matthew J. Berryman}
\begin{document}
\maketitle

\section{knitr example}

stray & test

\end{document}

(saved as example.Rnw)

where it continually re-runs compilation, seemingly

{
	"resource": "/Users/matthew/code/CBB/mfxlm-report/example.tex",
	"owner": "LaTeX",
	"severity": 4,
	"message": "File `example.out' has changed.\n(rerunfilecheck)\tRerun to get outlines right\n(rerunfilecheck)\tor use package `bookmark'.\n",
	"source": "LaTeX",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 1,
	"endColumn": 65536
}

I'm afraid I cannot get the rest of the output as it goes past too quickly with removal of the extra R code from the ~/.Rprofile file

@jlelong
Copy link
Collaborator

jlelong commented Jan 20, 2021

Now, it makes sense. This issue is actually related to #2237.
The whole problem comes from the file knitr.sty not being listed as an OUTPUT file in main.fls but only as an INPUT file. Whereas there are tricks to add a file as INPUT (see #2479), adding a file as OUTPUT is far more complicated as LaTeX provides no direct way to open a file in append mode.

What are your settings for latex-workshop.latex.autoBuild.run and latex-workshop.latex.autoBuild.cleanAndRetry.enabled?

@matthewberryman
Copy link
Author

matthewberryman commented Jan 20, 2021 via email

@jlelong
Copy link
Collaborator

jlelong commented Jan 20, 2021

Regarding #2487 (comment) the infinite loop comes from "latex-workshop.latex.autoBuild.cleanAndRetry.enabled": true. Setting it to false solves the issue, see https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-workshoplatexautoBuildcleanAndRetryenabled. This is because the .tex file is regenerated by R every time and therefore is considered by latexmk to have changed.

To solve the knitr.sty problem, instead of tweaking latex-workshop.latex.watch.files.ignore, you can set "latex-workshop.latex.autoBuild.run": "onSave", see https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#latex-workshoplatexautobuildrun

@tamuratak
Copy link
Contributor

tamuratak commented Jan 22, 2021

@jlelong I am positive on adding knitr.sty to latex-workshop.latex.watch.files.ignore by default. What do you think?

I have added an entry to FAQ.

@matthewberryman
Copy link
Author

Thanks for the suggestions. From my perspective I would like to be able to use the default options regardless of type of document (.tex, .Rnw single file, or master/child(ren) .Rnw with that useful knitr opt set). From that perspective, adding knitr.sty to the ignore files seems like a sensible proposition to solve that trigger of a loop, however I understand the other trigger (.tex not being the original source file but rather one transpiled from the original .Rnw source) may be more difficult. In the mean time I'm still pretty happy, so thanks for the advice.

@jlelong
Copy link
Collaborator

jlelong commented Jan 22, 2021

@tamuratak Adding knitr.sty to latex-workshop.latex.watch.files.ignore sounds like a good plan.

@jlelong
Copy link
Collaborator

jlelong commented Jan 22, 2021

It looks we have already considered to stop watching *.sty files #1788. I suspect that we left a typo in

https://github.com/James-Yu/LaTeX-Workshop/blob/b43e11366bd9dfaa36800646c73dec8d3c13aa94/package.json#L1092-L1093

We probably meant "**/*.sty" instead of "**.*.sty"

Repository owner locked as resolved and limited conversation to collaborators Feb 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Issue suggests an enhancement question Issue represents a question
Projects
None yet
Development

No branches or pull requests

3 participants