Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
突出显示knitr.RMD文档中的代码_R_Knitr_R Markdown - Fatal编程技术网

突出显示knitr.RMD文档中的代码

突出显示knitr.RMD文档中的代码,r,knitr,r-markdown,R,Knitr,R Markdown,我一直在阅读Rstudio Markdown教程,试图找出如何在.rmd文件中对我的代码进行语法高亮显示,但我想不通。有人知道怎么做吗?我现在的输出目标是.html,但如果需要的话,这可以改变。谢谢 我尝试的一个小代码片段。页面文本工作正常,但代码未突出显示: --- title: Eve Historical Market Analysis author: date: 12/3/18 output: prettydoc::html_pretty: theme: cayman

我一直在阅读Rstudio Markdown教程,试图找出如何在.rmd文件中对我的代码进行语法高亮显示,但我想不通。有人知道怎么做吗?我现在的输出目标是.html,但如果需要的话,这可以改变。谢谢

我尝试的一个小代码片段。页面文本工作正常,但代码未突出显示:

---
title: Eve Historical Market Analysis
author: 
date: 12/3/18
output:
  prettydoc::html_pretty:
    theme: cayman
    highlight: github
---
```
library(rmarkdown) #used for syntax highlighting in this document
library(shiny)
```
#read in file of item ids from website and parse
```
url = "http://eve-files.com/chribba/typeid.txt"
df = read_fwf(url, fwf_empty(url), skip = 2)
colnames = read_table(url, n_max = 1)
names(df) = names(colnames)

只需按如下方式修改r代码块,我希望它能产生您想要的结果

```{r, echo=FALSE}
library(rmarkdown) #used for syntax highlighting in this document
library(shiny)
```
#read in file of item ids from website and parse

```{r code, eval=FALSE}
url = "http://eve-files.com/chribba/typeid.txt"
df = read_fwf(url, fwf_empty(url), skip = 2)
colnames = read_table(url, n_max = 1)
names(df) = names(colnames)
```
输出:


是否要运行代码?或者只是为了展示示例代码?目前,因为您没有“您没有将代码放入一个r块中”这是不应该运行的-这只是我文件顶部的一个片段,显示了我迄今为止所做的尝试。@s.brunel我觉得“``表示一个r块。这不正确吗?@Rilcon42``不表示R块,除非在```之后包含
{R}
,或者在您的示例中包含
{R,eval=FALSE}
(请参见第四个示例)。我想这正是你要找的。非常有用,在RStudio中,单击
Help
Cheatsheets
R Markdown cheatsheet