在 RStudio 中的 R markdown 中,使用 bash 语言时如何防止源代码从 pdf 页面运行?

发布于 2025-01-20 15:30:37 字数 862 浏览 8 评论 0原文

我正在使用 Bookdown 和 RStudio 编写一本技术书籍。我的代码块主要使用 bash。一切工作正常,除了当我将书导出为 pdf 时,源代码部分脱离“盒子”,甚至页面(如果足够长)。我读过很多使用r语言时的解决方案,但是当使用bash语言时这些解决方案都不起作用。

这是我在 .Rmd 文件开头的代码:

```{r, global_options, include=FALSE}
knitr::opts_chunk$set(message=FALSE, eval=FALSE, 
tidy.opts=list(width.cutoff=60), tidy=TRUE)
```

然后当我编写代码块时:

```{bash}
mongodump --uri="mongodb+srv://cluster0.rh6qzzz.mongodb.net/" --db sample_mflix --username my_username
```

生成的输出如下所示(请参见行尾): example_1example_2

我想避免这种情况,但我还没有找到解决方案。

I'm writing a technical book using Bookdown and RStudio. My code chunks are mainly using bash. Everything works fine except when I export the book to pdf, then the source code is partially out of the "box" and even the page if this is long enough. I have read a lot of solutions when r language is used, but none of these solutions works when bash language is used.

Here is my code at the beginning of the .Rmd file:

```{r, global_options, include=FALSE}
knitr::opts_chunk$set(message=FALSE, eval=FALSE, 
tidy.opts=list(width.cutoff=60), tidy=TRUE)
```

And then when I write the code chunk:

```{bash}
mongodump --uri="mongodb+srv://cluster0.rh6qzzz.mongodb.net/" --db sample_mflix --username my_username
```

The outputs were produced as shown below (see the end of line):
example_1
example_2

I would like to avoid this, but I have not found the solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文