为什么 grep() 在 readLines() 之后不起作用?
Why is grep() not working after readLines()?
我用 R 开发了一个程序来阅读在线提供的报告,前两行是:
page1 <- readLines("http://reportviewer.tce.mg.gov.br/default.aspx?server=noruega&relatorio=SICOM_Consulta/2013_2014/Modulo_AM/UC03-LeisOrc-RL&municipioSelecionado=3100203&exercicioSelecionado=2014")
line1 <- grep("Leis Autorizativas",page1)
程序的其余部分工作正常,我得到了我需要的数据。然后我尝试调整它以阅读不同的报告,但这次第二行不起作用:
page2 <- readLines("http://reportviewer.tce.mg.gov.br/default.aspx?server=noruega&relatorio=SICOM_Consulta/2013_2014/Modulo_AM/UC08-ConsultarDecretos-RL&municipioSelecionado=3101607&exercicioSelecionado=2013")
line2 <- grep("Decretos de Alterações",page2)
第一种情况下 'page1' 是字符向量,第二种情况下 'page2' 是 large 字符向量。这种差异是否可能导致问题?如果是这样,有人可以提示如何修复它吗?
(使用 htmltab() 或 readHTMLtable() 没有产生好的结果)
谢谢。
那是因为"Decretos de Alterações"不是完全由ascii字符组成的。
如果你尝试
page2 <- readLines("http://reportviewer.tce.mg.gov.br/default.aspx?server=noruega&relatorio=SICOM_Consulta/2013_2014/Modulo_AM/UC08-ConsultarDecretos-RL&municipioSelecionado=3101607&exercicioSelecionado=2013")
grep("Decretos de Alterações ", page2)
[1] 366
有效。
要知道要替换的号码:
utf8ToInt("ç")
[1] 231
然后将结果数字放在 &
和 ;
之间,并替换您的非 ascii 字母。
最佳
科林
我用 R 开发了一个程序来阅读在线提供的报告,前两行是:
page1 <- readLines("http://reportviewer.tce.mg.gov.br/default.aspx?server=noruega&relatorio=SICOM_Consulta/2013_2014/Modulo_AM/UC03-LeisOrc-RL&municipioSelecionado=3100203&exercicioSelecionado=2014")
line1 <- grep("Leis Autorizativas",page1)
程序的其余部分工作正常,我得到了我需要的数据。然后我尝试调整它以阅读不同的报告,但这次第二行不起作用:
page2 <- readLines("http://reportviewer.tce.mg.gov.br/default.aspx?server=noruega&relatorio=SICOM_Consulta/2013_2014/Modulo_AM/UC08-ConsultarDecretos-RL&municipioSelecionado=3101607&exercicioSelecionado=2013")
line2 <- grep("Decretos de Alterações",page2)
第一种情况下 'page1' 是字符向量,第二种情况下 'page2' 是 large 字符向量。这种差异是否可能导致问题?如果是这样,有人可以提示如何修复它吗?
(使用 htmltab() 或 readHTMLtable() 没有产生好的结果)
谢谢。
那是因为"Decretos de Alterações"不是完全由ascii字符组成的。
如果你尝试
page2 <- readLines("http://reportviewer.tce.mg.gov.br/default.aspx?server=noruega&relatorio=SICOM_Consulta/2013_2014/Modulo_AM/UC08-ConsultarDecretos-RL&municipioSelecionado=3101607&exercicioSelecionado=2013")
grep("Decretos de Alterações ", page2)
[1] 366
有效。
要知道要替换的号码:
utf8ToInt("ç")
[1] 231
然后将结果数字放在 &
和 ;
之间,并替换您的非 ascii 字母。
最佳
科林