Knitr无法使用scan(dec =“,")编译块 [英] knitr fail compiling chunk with scan(dec=",")

查看:86
本文介绍了Knitr无法使用scan(dec =“,")编译块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用scan(dec =,")命令从Excel导入(复制并粘贴)一些数据,并用逗号作为小数点,但是在编译此块时,knitr出现了问题:

What I'm trying is import (copy&paste) some data from Excel with comma as decimal points by using scan(dec=",") command, but I have a problem with knitr when compiling this chunk:

<<>>=
conc<-scan(dec=",")
9,562445749
37,66119516
72,9103195

@

我收到此错误:第22行:意外的','

I get this error: Line 22: Unexpected ','

感谢您的帮助

推荐答案

在这种情况下,scan()要求您以 interactive 方式运行它(例如,它等待空白行以终止输入) ),而knitr/Sweave以非交互方式运行R代码.通常,您应该避免需要交互的代码.换句话说,您应确保无需人工干预即可执行代码.例如,无论环境如何,它都可以自行运行:

In this case scan() requires your to run it in an interactive fashion (e.g. it waits for a blank line to terminate input), whereas knitr/Sweave runs R code in a non-interactive fashion. In general you should avoid code that requires interaction; in other words, you should guarantee the code can be executed without human interaction. For example, this runs on itself regardless of the environment:

conc <- scan(dec=",", text='9,562445749
37,66119516
72,9103195
')

为了可重复的研究,避免涉及人工干预的代码尤为重要,因为干预意味着结果不能由代码本身确定(取决于每次运行的人工输入).

It is especially important to avoid code which involves with human intervention for the sake of reproducible research, because intervention means the results can not be determined by code itself (depending on human input for each run).

这篇关于Knitr无法使用scan(dec =“,")编译块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆