如何修复“输入中无可用行"的 R 错误? [英] How to fix the error in R of "no lines available in input"?

查看:38
本文介绍了如何修复“输入中无可用行"的 R 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做的是从数百个链接中读取数据,其中一些链接不包含数据,因此,如下代码:

What I need to do is to read data from hundreds of links, and among them some of the links contains no data, therefore, as the codes here:

urls <-paste0("http://somelink.php?station=",station, "&start=", Year, "01-01&etc")
myData <- lapply(urls, read.table, header = TRUE, sep = '|')

弹出一个错误,说输入中没有可用的行",我试过使用try",但出现同样的错误,请帮忙,谢谢.

an error pops up saying "no lines available in input", I've tried using "try", but with same error, please help, thanks.

推荐答案

这里有 2 个可能的解决方案(未经测试,因为您的示例不可重现):

Here are 2 possible solutions (untested because your example is not reproducible):

使用try:

myData <- lapply(urls, function(x) {
  tmp <- try(read.table(x, header = TRUE, sep = '|'))
  if (!inherits(tmp, 'try-error')) tmp
})

使用tryCatch:

myData <- lapply(urls, function(x) {
  tryCatch(read.table(x, header = TRUE, sep = '|'), error=function(e) NULL)
})

这篇关于如何修复“输入中无可用行"的 R 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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