我是一个顽固的使用者而=不是一直使用<-,显然很多R程序员都会对此不以为然.我写的formatR包可以替换=为<-基于parser包.正如你们中的一些人可能知道的那样,parser几天前在CRAN上成了孤儿.虽然现在又回来了,但这让我对依赖它犹豫不决.我不知道是否有另一种方式来安全地更换=有<-,因为不是所有=的意思分配,例如fun(a = 1).正则表达式是不太可靠(见第18行中的mask.inline()函数formatR),但我肯定会欣赏它,如果你能提高矿井.也许这个codetools包可以帮忙吗?
一些测试用例:
# should replace
a = matrix(1, 1)
a = matrix(
1, 1)
(a = 1)
a =
1
function() {
a = 1
}
# should not replace
c(
a = 1
)
c(
a = c(
1, 2))
Run Code Online (Sandbox Code Playgroud) 如何mouseover text在R闪亮数据表显示中为列名创建.我正在尝试为用户提供一些文本来理解列名称.我也检查了DT包,我找不到解决方案.我可以为列名创建标签,并在用户选中一个框时显示所有这些标签,这需要大量的空间,我不希望这样.有小费吗?
环境:
R v 2.15.1在Mac OS 10.8.2上,平台x86_64-apple-darwin9.8.0/x86_64(64位),RStudio IDE设置为使用UTF-8作为其默认编码.操作系统也使用UTF-8.
> Sys.getlocale(category = "LC_ALL")
[1] "sk_SK.UTF-8/sk_SK.UTF-8/sk_SK.UTF-8/C/sk_SK.UTF-8/sk_SK.UTF-8"
Run Code Online (Sandbox Code Playgroud)
目的:
从R HTML(.Rhtml)文件生成HTML文件,其中包含带有扩展拉丁字符的图,例如š或č.
问题:
当我点击Knit HTML时,输出如下所示:
plot(1:2, main = "š?")
## Warning: conversion failure on 'š?' in 'mbcsToSbcs': dot substituted for
##
## Warning: conversion failure on 'š?' in 'mbcsToSbcs': dot substituted for
##
## Warning: conversion failure on 'š?' in 'mbcsToSbcs': dot substituted for
##
## Warning: conversion failure on 'š?' in 'mbcsToSbcs': dot substituted for
## <8d>
**Plot with correct characters despite the …Run Code Online (Sandbox Code Playgroud) 我试图以svg格式保存ggplot2图.我没有使用ggsave函数,因为绘图是作为knitr文档的一部分生成的 - 我为绘图指定的设备是'svg'.
问题是原始图中的文本元素在svg文件中显示为路径,至少在inkscape中打开时.svg的源代码看起来不包含任何文本.
我的绘图功能在一个单独的文件中定义:
## @knitr plot_histogram
ggplot(mainFrame[complete.cases(mainFrame),])
+ geom_boxplot(aes(x=source, y = pPfam, fill = source))
+ scale_y_continuous(limits = c(0,1))
Run Code Online (Sandbox Code Playgroud)
在knitr文档中,我调用该函数并使用'svg'设备保存图像.
```{r plot_histogram, dev = 'svg', fig.width= 7, fig.height=4, fig.show='hold', fig.path="figure/summary"}
```
Run Code Online (Sandbox Code Playgroud)
所以我不知道如何告诉'svg'设备或ggplot2我想在保存svg时保留文本?如果可以解决问题,我也很乐意使用其他图形设备.
提前谢谢了.
我想知道SAS中是否有相同的R Markdown?或者如何在SAS中这样做?我想在下面有彩色SAS代码及其结果.
链接到R Markdown:http://rstudio.org/docs/authoring/using_markdown
在一个书籍项目中,我有很多输出我想缩写,只选择一行的子集,并添加...以指示某些输出已被省略.例如,在输出中summary(lm()),我可能只想打印系数表,并使其显示如下:
>summary(lm(Sepal.Length ~ Species, data=iris))
...
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.0060 0.0728 68.762 < 2e-16 ***
Speciesversicolor 0.9300 0.1030 9.033 8.77e-16 ***
Speciesvirginica 1.5820 0.1030 15.366 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
...
Run Code Online (Sandbox Code Playgroud)
我编写了以下输出钩子,它使用块选项,output.lines=并接受一个数字,n,意味着只打印行1:n,有点像head():
# get the default output hook
hook_output <- knit_hooks$get("output")
knit_hooks$set(output = function(x, options) {
lines <- options$output.lines
if (is.null(lines)) { …Run Code Online (Sandbox Code Playgroud) 我想shiny第一次使用.每当我试图运行示例shiny应用程序RStudio崩溃与致命错误.我得到的错误是:
Error in withCallingHandlers(tracatch(evalq(funtion (hash=TRUE, parent=parent.frame(), :
object '.rcpp_warning_recorder' not found.
Run Code Online (Sandbox Code Playgroud)
我正在使用R version 3.1.2 (2014-10-31)- "南瓜头盔".有人可以帮忙吗?
这个问题类似于一致的代码html内联和与knitr的块.而不是.Rhtml文档,我想在R Markdown文档中突出显示内联R代码,例如,在`r "plot(cars, main = 'A scatterplot.')"`通过rmarkdown编译之后,plot应该突出显示标记.默认情况下,R代码块是语法突出显示的,但无法突出显示内联R代码.
我正在使用RMarkdown创建一个闪亮的ioslide演示文稿.我的一些幻灯片实际上并不适合一页并被截断.
由于这是一个HTML输出,我想添加一个滚动条,使我的长幻灯片可滚动.
我一直在谷歌搜索,并找到一个部分解决方案,使R代码块可滚动.但是我想让我的幻灯片可以滚动,无论内容如何.
这是一个玩具Rmd示例,幻灯片不适合在一个页面上:
---
title: "Untitled"
date: "30 October 2018"
output: ioslides_presentation
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Shiny Presentation
- A very long
- and boring
- list of
- bullet points
- just a
- toy example
- obviously
- not over yet
- almost
- not quite
- finally
- out of frame!
Run Code Online (Sandbox Code Playgroud)
我想使这个幻灯片可滚动,因为它不适合一页.
编辑:我不确定为什么这会被大量投票 - 会赞赏一个建设性的评论:)在此期间,我确实删除了css可能带来不熟悉rmarkdown的人的标签.
我想用R之类的东西将一大块Python代码传递给Python system('python ...'),我想知道在这种情况下是否有一种简单的方法来模拟python控制台.例如,假设代码是"print 'hello world'",我怎样才能在R中获得这样的输出?
>>> print 'hello world'
hello world
Run Code Online (Sandbox Code Playgroud)
这只显示输出:
> system("python -c 'print \"hello world\"'")
hello world
Run Code Online (Sandbox Code Playgroud)
谢谢!
顺便说一句,我在r-help中问过但还没有得到回复(如果我这样做,我会在这里发布答案).