I am currently writing my bachelor thesis using Rmarkdown, and whenever i make changes I knit to PDF to check how it looks etc.
It worked perfectly until I wanted to check some small changes and after that I canĀ“t get it to knit, this is the error message I get:
output file: bbb.knit.md
! Text line contains an invalid character.
l.28 pdftitle={^^K
space{3.5in} Portfolio},
Error: Failed to compile bbb.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See bbb.log for more info.
Bare in mind that I am learning R while writing my thesis so I do have a very low level of knowledge. Does anyone have any suggestions for where the mistake might be? Line 28 has no text by the way.
I have read some suggestions about deleting the auxiliary file but I dont even know what that is or where to find it, or if it could cause me any problems deleting it.
Hope someone has some tips as wasting a lot of time on this is the last I need right now! Thanks
The solution was to change the title input in YAML from "\vspace{3.5in} Portfolio"
to only "Portfolio".
Related
I am using pycodestyle_magic as a linter in Jupyter. I am following the instructions at
https://github.com/mattijn/pycodestyle_magic
But I get error with 1-cell checking be it '%%pycodestyle' or '%%flake8'.
1st ERROR
# 1st CELL
%load_ext pycodestyle_magic
# 2nd CELL
%%pycodestyle
a=1
print(a)
2nd ERROR
# 1st CELL
%load_ext pycodestyle_magic
# 2nd CELL
%%flake8
a=1
print(a)
1st ERROR
I'm basing this on your image you posted for '1st error' and not the inaccurate code you posted:
Note that the error in your first error was saying line magic and not cell magic because it was not looking for cell magic anymore. You can see it will look for cell magic on the first line of a cell by putting in %%fake_magic as a first line and then 2 + 2 as a second line of cell. Running that you'll see UsageError: Cell magic %%fake_magic not found.
Hence, your first 'error' is that you are missing that the first line of the cell where you want to use cell magic becomes special. You cannot have something else on the first line where you want to use cell magic, even if it is commented out. In the image, you have #%%flake8 above %%pycodestyle. If you remove that line, it should work.
2nd ERROR
I'm basing this on your image you posted for '2nd ERROR' and not the inaccurate code you posted:
You've stumbled upon a bug currently involving flake8. (Maybe same or more bugs seem to prevent the %%flake8 magic from working at all for now, see comments.)
The solution/workaround is very similar to the '1st ERROR'. Remove the line you were trying to comment out because it being there is causing an issue.
The reasoning appears to be complex about the way the %%flake8 cell magic appears to work behind the scenes so that you cannot have comments in the code content at this time or it won't work. (And the second time it sees that comment symbol, it throws the error you see.) This bug has been reported here.
But the solution/work-around for now is straightforward. Remove the complexity you added, and see if it works.
In case of the %%flake8 magic, running the demo notebook as shown there doesn't work as shown, and so there is indeed a bug in the current version that was introduced by actually a bug in flake8 that the extension uses, see the specific comment here and the link to the underlying issue over at the flake8 repo. (In fact the extent that it doesn't work may be greater than the notebook reflects because as discussed in the comments, even cells without commented lines fail to report any formatting issues. The demo actually doesn't have any without and so I got distracted noting it only didn't show the buffer error for the first one in the demo notebook but since it had a commented line I thought it was still related.)The other way to workaround it at present is to install an older version of flake8 as pointed out here. The solution was merged though and should be available soon, and so just avoiding the triggering code in simple cases like yours is probably easier.
Note about the inaccurate code:
Post code for what gave you the issue, not what you think gave you the issue. Part of why you are asked to provide code as text the way you ran it, it is so those looking into it can run it the same way. Plus they don't have to type and can easily run it as you did. Beyond that, there's more reason behind it: you can try to see if what you observed originally matches what you are seeing now.
If you had run what you posted under the heading '1st ERROR' as the code block text, you would have seen it without the error you showed in your image. Usually you'd then discern the error/difference yourself. In other words, starball's comment was trying to point you to why you should be doing that, and sorted that 1st error out yourself. That would ultimately make your point about the fragile nature of %%flake8 magic have more impact because it isn't diluted by report of an error that isn't really an error. Plus, you may have realized what was necessary to avoid '2nd ERROR' because that code block works without error no matter how many times you run it.
Technical notes:
Anyone wishing to try out pycodestyle_magic with some of this code and the demo notebooks can click here to launch such a session served via the mybinder.org. service with most things necessary already set up. Once the session starts up in the classic Jupyter notebook interface, you need to do some further preparation to use pycodestyle_magic. As detailed here, you can install it with pip install flake8 pycodestyle_magic. So open a new notebook with the Python kernel backing it using New drop down on the upper right side and then choose the Python3 kernel. When it opens, make a cell that has %pip install flake8 pycodestyle_magic and run it. Then put %load_ext pycodestyle_magic as a cell and run that. You can now try the magic with code or pull the demo notebooks over and run those.
I've encountered a very bizarre problem with my R scripts. I had a bunch saved in a folder, and after reinstalling R (which was itself having some issues), the rather large scripts I had can easily open in R, but appear to have no text on them (this is despite it clearly labeled as an R document in the folder and being 26kb). Yet when I upload my scripts in a message on Slack, it appears perfectly fine.
Here is what my R script looks like presently:
And this is what it should look like:
I'm thinking it has something to do with the way R is reading the text in the script, but I couldn't find any answers online that were helpful. I would greatly appreciate any advice, as I dont' want to have to recreate all of these using Slack of all things...
I figured it out with some tinkering and it was a rather simple fix that mirrored what I thought the issue was. Apparently my RStudio program was set to read the text in CP936 format. I set it to system default:
And viola! My text is now back!
I get the error message:
! Missing $ inserted.
<inserted text>
$
l.4 .... Graphic was created using BioRender.com.}
\label{fig:label}
and am going absolutely bonkers trying to resolve the issue. The text in question is in a figure caption, and I have checked all my math expressions preceding the 'hinted' line. All my math expressions are correctly closed with $'s; I've removed all underscores (_); and I even removed a link to a website.
Is there a way for me to at least be directed to where the problem is located in my file?
I'm using Rmarkdown, papaja::apa6_pdf.
Kind regards to anyone who can help.
EDIT
Thanks for the responses.
I've managed to narrow down the problem. Here is a sample of the chunk I'm having issues with:
{r fig-label, include = TRUE, fig.cap="**This is the title of the image.** (**A**) Explanation A with a special character alpha $\\alpha$5.(**B**) Explanation B with a supercript degree symbol 60^o^C."}
if (Sys.info()[1]=="Windows"){
knitr::include_graphics("C:\\Path\\To\\My\\Image\\File.png")
} else if (Sys.info()[1]=="Mac OS"){
knitr::include_graphics("Path To My Image/File.png")
}
The problem arises with my supercripted degree symbol. Windows can effortlessly render the image to the correct size with all the text options (boldface, special characters, etc). My Mac fails to do so, and even removing the degree symbol makes my Mac include the ** around the text I want to have as boldface. Windows can make the image the correct size, Mac prints the image way too big.
I've followed all the debugging options explained at https://yihui.org/tinytex/r/#debugging.
I very much want (need) this to work on my Mac, so can anyone give me some advice on how I can get my mac to properly knit my markdown document?
Again, kind regards to anyone/everyone who is able to help or offer advice. Let me know if you need additional information.
it's been a few days that im trying to run my Rmd on Kaggle, but it simply doesn't work.
The main reason (I guess) is that, somehow the console is reading the code as an R code, but im sure that I'm using Rmarkdown.
Therefore, the console reads a Text line as a code line, giving me the code error below:
Also, i tried to copy and edit other's people markdown, but i keep getting the same error line.
You can check my code here: https://www.kaggle.com/badluckmath/kernel4c85aae59c/edit/run/39891200
He's working perfectly on my Rstudio.
I'm looking for a huge help here, please!
I've been stuck with this for a week!
If i press the buttom to run code, it will simply give me this error message.
For that, i still don't know the solution. But since this is a premade Rmarkdown and i knew that it works, i simple used the Save (Commit) options and at the end, it worked.
I am working on packing my course notes together using bookdown. When I try to view my chapter updates using bookdown:::serve_book() or simply knitting the document (supposedly a shortcut to preview_chapter) I get the error message below. And only after updating.
Error in basename(with_ext(nms, ".html")) : path too long
Calls: <Anonymous> ... <Anonymous> -> <Anonymous> -> split_chapters -> basename
Please delete MATH456_notes.md after you finish debugging the error.
Execution halted
If I remove the mentioned .md file, AND clean the whole project using rmarkdown::clean_site(), it will compile just fine. But if I make changes, and try to view the update I get the following message.
Any ideas what is going on? I really don't want to rebuild the entire book every time I want to preview the current chapter.
If i'm previewing the book, and make any small change, the auto-update/live preview also throws the same error.
I know this thread is old, but maybe my answer may help others in the future. :) So for all of you who still encounter this error:
For me, the problem can be fixed by checking all headings. Most likely you inserted a hashtag # in the wrong place (i.e. in the body text) without closing it, so Bookdown detects a new main chapter (i.e. level 1) that has an extremely long heading name.
I would recommend saving the index.rmd in a second backup file and then deleting each chapter individually, starting at the bottom. Once your book renders again with no problems, you will know which chapter is causing the problem. Watch out for problematic hashtags # and headings there.