Headings not working in my R markdown file - r

I recently finished my R notebook, and noticed something once I decided to knit the markdown file. None of the headings or bullet points were working! I had to install XQuartz to finish knitting the markdown file since I have a mac. Is this something that's normal or can I fix this?

I haven't seen your rmarkdown, but I suspect that you need to add a blank line above each heading. For example, putting a heading right after a list (or any other structure) sometimes results in problems:
1. First item
2. Second item
3. Third item
# First level heading
However, adding a blank line before each heading usually fixes the problem:
1. First item
2. Second item
3. Third item
# First level heading

Related

Jupyter Notebook cell stopped working as such

There is the first cell that is supposed to execute code as the rest, but somehow it's not even working at all.
The next cells are working properly, but this forst one doesn't recognize my input.
In the pictures provided you can see that the next cell recognizes my input as code and highlights the proper words in color. When I first opened the notebook it was alright, but it just stopped working for this first cell.
I have tried to close and reopen, interrupt kernel and everything in my hands.
Thank you very much for your time.
Cell was not stuck on an infinite loop. Somehow Jupyter Notebook stopped recognizing it as a code cell. Therefore you have to manually srt it back to code cell. See image.

What cause format change when copy and paste in rstudio?

#sample select
sample_frac(mydata,n%)#random select n% sample
##############data review####
Just copy above code into rstudio script, you will find 2 more tab added to the last line.
What cause it?
Edit
As mentioned by #Jay in the comments, the n% in the command is treated as a function and since it is not complete it indents the next line.
To further confirm, try with df %in% in the script or df >%> and hit enter to see the cursor goes to the next line with an indent.
To avoid that just complete the function there.
sample_frac(mydata,n)
OR
sample_frac(mydata, n %% somenumber)
whatever you are trying to do and it should be fine.
Original Answer
It did add 2 tab spaces in the code when pasting in the RStudio script. I tried to paste the same text in my notes, Pycharm editor but it did not add any extra tabs there. So it was sure that this is a RStudio issue.
It turns out it is the indentation settings in RStudio which is responsible for this. To change that:
Go to Tools -> Global Options. Click on the Code option on the left. You'll see this :
Uncheck Auto-indent code after paste
and click on OK.
Now try to paste the same text. Should be resolved.

Define what makes a code section in rstudio

Rstudio changed how a code section is defined. In version 0.99.902 code sections had to have some text behind the hash symbol. But now in version 1.0.136 if there are 5 hashes in a row it will define a new section.
Is there anyway to make it go back to the old way of defining sections? It isn't a big deal except I would mark my sections with hashes above and below the name and now it is creating 3x as many sections.
Old version:
New version:
I don't know if there's a way to recover the old behavior, but you could use + instead. In addition, you can put this in a code snippet (if you haven't already). In Preferences, go to the Code tab, scroll to the bottom and click the Edit Snippets button. Then add something like the following:
snippet hd
`r "# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
### HEAD ##########
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"`
Then, when you type hd followed by a tab (actually two tabs, since the first tab will bring up a few options that start with hd, but hd will be at the top, so you can just press tab twice) in your R script file, the following will appear:
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
### HEAD ##########
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Better yet, you can create a snippet that takes the heading text as an argument:
snippet hd
`r paste("# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
"### ", "${1:HEAD}", " ##########\n",
"# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", sep="")`
Then, when you type hd followed by two tabs, the HEAD text will be highlighted and you can just type in your actual heading text.
Unfortunately, this behavior has changed between RStudio v0.98.1091, v0.99.903 and the current release v1.0.136.
In RStudio v0.98.1091, 'empty' headers such as ##### were recognized as section headers.
This behavior was briefly changed with v0.99.903, such that some initial text was required for these to be recognized as section headers. A number of users were unhappy as this effectively broke code folding for users who were explicitly using standalone ##### blocks to create sections.
Because of that, the behavior was reverted in RStudio v1.0.136, and so now standalone ##### blocks are again recognized as section headers.

Rmarkdown & {knitr}: code chunk highlights in lists?

I have a two-level ordered list, and the output is identical to this post. My output is fine and looks how it should. My issue is the normal 'highlighting' of chunks disappears with 8 spaces, and the RMD source no longer 'recognizes' the chunks as such. The blank lines before and after the chunks are also indented (I found that I had to do this to get the desired output).
To illustrate this, I'm sharing the image below. The highlight is missing, and that same cursor position in other chunks gives a little button next to line:character in the bottom left rather than '(Top Level)'. If I bring the chunk indention in (from 8 spaces to 4) the code no longer lines up with the list in the output.
Is there any way to remedy this? Haven't had any luck searching online or going through the documentation. (If interested, the example comes from ISLR, Section 2.4, Exercise 8.)
Ok, got it working. For some reason hitting tab (four spaces) twice in R Studio causes the issue above. I suspect it has something to do with R Studio rather than R Markdown or {knitr}. The solution is this response by #Yihui, and relies on using the indent parameter. That will keep the highlight and recognition of the chunk as well as keeping everything aligned in the output.
I never thought to use the indent parameter as it's not listed in the {knitr} chunk options in the current R Markdown Reference Guide (here), and is only mentioned passively at the end of the Code Description section in the {knitr} chunk options (here).
I find that if I keep the indention of the code at one more indent level that the corresponding text, everything renders nicely:
1. One level of indention
* Two levels of indention
* Three levels of indention
* Four levels of indention
```{r,eval=FALSE}
Some("R code")
```

Inserting a Link to a Webpage in an IPython Notebook

How is this done? I'd like to have the link be in a markdown cell.
For visual learners:
[blue_text](url_here)
In case it is not a markdown cell, that is with what I went:
from IPython.core.display import display, HTML
display(HTML("""text"""))
Just another tip, using magic expression.
%%html
Showing Text
Improved. Thanks to the comment of calocedrus.
Here is the code I use in my python notebook when I want to insert a link to a webpage inside a markdown cell (in a python notebook).
[Clickable_visible_hyperlink](Hidden_landing_URL)
--note Here is the clickable hyperlink, you can change the value
This might help too, if you're looking to display a link programmatically.
from IPython.display import display, Markdown
display(Markdown("[google](https://www.google.com)"))
I also tried
display(HTML("""<a href="https://www.google.com>google</a>"""))
But somehow I was getting the object printed out, instead of the rendered version.
For programming in R, do the following when using Jupyter Notebook or Jupyter Lab - (using the R kernel). These steps will display a web link and an image in a Notebook markdown cell. The following shows a real-life example of some study notes using Jupyter Lab and R.
First open a markdown cell in Jupyter - can be a new markdown cell or an existing markdown cell. Then copy and paste the actual web address into a markdown cell. This will provide an active link to that website from the Notebook.
Step 2, from that website, copy the image that you want to view in the Notebook. This image should be in a standard image format (.png, .jpg, etc ). Paste this image into the same folder on the computer where the Jupyter notebook file is located. Note: if the image is later deemed too large or small, then resize using any graphics software available - and then save the changed image into this same folder. Note: it is important to know the name of this image file.
Next, paste the name of the image file between the quotation marks in the following code: . If this file in not within your existing jupyter notebook working directory, then a path to the image file will need to be placed inside the quotation marks.
Step 3, also included is an example of the line of code (also used in Notebook markdown cell) to create colored text in markdown cells. In this line of code, the double ## character results in the second largest font being used in Jupyter. Smaller text using more of these characters - with #### being the smallest. One # results in the largest font output.
Last, be sure to close and run the markdown cell to view the output. The code for the markdown cell follows, and further below shows the output from the Notebook.
Code in Markdown cell:
"https://www.tensorflow.org/images/colab_logo_32px.png" # link to website
<img src="tidyflow.png" /> # The image file (This path is the same folder as Notebook file)
## <font color = cyan> Some Colored Text in Notebook Markdown Cell </font> # colored text
Output:

Resources