Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.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
R 控制插入符号html输出中的位数_R_Knitr_R Caret - Fatal编程技术网

R 控制插入符号html输出中的位数

R 控制插入符号html输出中的位数,r,knitr,r-caret,R,Knitr,R Caret,我有密码 ```{r comment=NA} require(caret) set.seed(42) tc <- trainControl(method="cv") m <- train(x=longley[,-ncol(longley)], y=longley[,ncol(longley)], method="pls") m ``` 但是在html生成过程中,所有数值都是四舍五入的 如何在html中保留与控制台中相同的输出 进一步调查

我有密码

```{r comment=NA}
require(caret)
set.seed(42)
tc <- trainControl(method="cv")
m <- train(x=longley[,-ncol(longley)],
           y=longley[,ncol(longley)],
           method="pls")
m
```
但是在html生成过程中,所有数值都是四舍五入的

如何在html中保留与控制台中相同的输出

进一步调查和解决办法

我使用RStudio。刚刚启动R会话
getOption(“数字”)
返回7。但在生成html时,数字输出是四舍五入的。控制台输出正常。
如果我在代码块中设置了
选项(digits=7)
,那么html和控制台输出将变得相同且正确


我不能理解这种行为,但它是有效的。这是一个bug还是一个特性?

问题是我还没有完全决定如何处理它。我很可能会停止更改knitr中的默认位数(即接受此设置)。在此之前,您需要在文档开头放置
选项(数字=7)

您是否在
knitr
文档中的任何位置设置了
选项(数字=)
?否。这是完整的代码,应该可以复制。您能用html复制相同的输出吗?如果我添加行选项(数字=3),则在html生成过程中返回一个错误“无效参数数字”。@DrDom我最终从knitr中删除了
options(数字=4)
;开发版本将不再重置
数字
选项。
Partial Least Squares 

16 samples
 6 predictors

No pre-processing
Resampling: Bootstrapped (25 reps) 

Summary of sample sizes: 16, 16, 16, 16, 16, 16, ... 

Resampling results across tuning parameters:

  ncomp  RMSE   Rsquared  RMSE SD  Rsquared SD
  1      1.39   0.836     0.552    0.155      
  2      1.08   0.899     0.387    0.103      
  3      0.592  0.976     0.187    0.0183     

RMSE was used to select the optimal model using  the smallest value.
The final value used for the model was ncomp = 3.