设为首页收藏本站获取积分奖励

R语言中文网

 找回密码
 立即注册
查看: 3288|回复: 4

[问题求助] 关于用R生成报告(新人求点拨~)

[复制链接]
发表于 2017-5-9 20:21:23 | 显示全部楼层 |阅读模式
各位大神好~

第一次进来求助~

最近学习的《R in Action》(R语言实战),第二十二章中,”用R和Markdown创建报告“部分,已经下载了Rstudio并且按照代码清单创建了.Rmd(即以下附文中women.Rmd)文件,然后教材中说使用"rmarkdown"包中的"render"函数生产HTML的报告,这时候R就报错说找不到函数中提到的.Rmd文件。。。
教材作者感觉在这一章都不怎么上心,真是苦,找不到解决办法。。。真心求助~

附:
第一部分(.Rmd文件内容)
---
title: "Regression Report"
output:
  html_document: default
  word_document: default
---
```{r echo=FALSE,results='hide'}
n <- nrow(women)
fit <- lm(weight~height,data=women)
sfit <- summary(fit)
b <- coefficients(fit)
```
Linear regression was used to model the relationship between weight and height in a sample of `r n`women.The equation **weight=`r b[[1]]`+`r b[[2]]`*height**accountded for `r round(sfit$r.squared,2)`%of the variance in weights.The ANOVA table is given below.

```{r echo=FALSE,results='asis'}
library(xtable)
options(xtable.comment=FALSE)
print(xtable(sfit),type="html",html.table.attributes="border=0")
```
The regression is plotted in the following figure.
```{r echo=FALSE,fig.width=5,fig.height=4}
library(ggplot2)
ggplot(data=women,aes(x=height,y=weight))+geom_point()+geom_smooth(method="lm")
```

第二部分(R中的代码及报错内容)
>library(rmarkdown)
Note: no visible global function definition for 'radixsort'
>
>render("women.Rmd","html_document")
Error in tools::file_path_as_absolute(input) :
  file 'women.Rmd' does not exist
此外: Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
  path[1]="women.Rmd": 系统找不到指定的文件。


回复

使用道具 举报

发表于 2017-5-10 23:39:26 | 显示全部楼层
women.Rmd,这个文件在工作目录内吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-5-11 18:19:43 | 显示全部楼层
Rocky_Xin 发表于 2017-5-10 23:39
women.Rmd,这个文件在工作目录内吗?

赞啊!!
以前一直不知道怎么让R读取这个文件,原来要放到“文档”里~

不过又出了点问题。。。

麻烦您看下~

> render("women.Rmd","html_document")

processing file: women.Rmd
  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |.........                                                        |  14%
  ordinary text without R code

  |                                                                       
  |...................                                              |  29%
label: unnamed-chunk-1 (with options)
List of 2
$ echo   : logi FALSE
$ results: chr "hide"
Quitting from lines 9-13 (women.Rmd)
Error in (function (filename = "Rplot%03d.png", width = 480, height = 480,  :
  图形API版本不相符



(这个”图形API版本不相符“的报错我在使用 "lattice" 包的 histogram 函数时候也出来了。。。百度也找不到什么靠谱结果。。。)
回复 支持 反对

使用道具 举报

发表于 2017-5-12 21:58:17 | 显示全部楼层
刘思遥 发表于 2017-5-11 18:19
赞啊!!
以前一直不知道怎么让R读取这个文件,原来要放到“文档”里~

Rmd文档里面是不是有图片?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-5-13 17:22:57 | 显示全部楼层
Rocky_Xin 发表于 2017-5-12 21:58
Rmd文档里面是不是有图片?

啊问题算是解决了~您一提到图片我就试了下别的画图函数,发现我的R画图函数都出现了:“错误:图形API版本不相符”。。。


用别人的R试了下没有问题,只能重装了R,现在都没有问题了可以画图了。


但是一直没搞清楚以前出问题的原因。。。


还是多谢了!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Archiver|R语言中文网    

GMT+8, 2024-4-20 07:52 , Processed in 0.028828 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表