httr CSV内容读取为整数而不是双精度 [英] httr CSV Content reading as integer instead of double
问题描述
我正在尝试从在线来源使用httr导入csv,一切都很好,除了它将一列读为整数(当它应该是双精度值时会导致这些值显示为NA)
I'm trying to import a csv using httr from an online source, everything is fine except for it's reading a column as integer when it should be a double resulting in those values to show up as NA
我正在使用并收到以下问题.
I'm using and getting the below issue.
getdata<-GET(粘贴("https://rest.zuora.com/v1/files/",r$FileId,sep =''),auth)发票<-content(getdata,type ="text/csv")
Parsed with column specification:
cols(
Account.external_id__c = col_integer(),
Invoice.Amount = col_double(),
Invoice.Balance = col_integer(),
Invoice.CreatedDate = col_datetime(format = "")
)
Warning: 171 parsing failures.
row col expected actual
2475 Invoice.Balance no trailing characters .4
2726 Invoice.Balance no trailing characters .71
3197 Invoice.Balance no trailing characters .3
3287 Invoice.Balance no trailing characters .5
3350 Invoice.Balance no trailing characters .1
.... ............... ...................... ......
See problems(...) for more details.
感谢您的任何帮助,谢谢.
Any help is appreciated, thanks.
推荐答案
当您传递 type =文本/csv"
.您可以将参数传递给 content
中的 read_csv
,幸运的是, read_csv
允许您定义要导入的csv的列类型.>
The httr::content
function uses readr::read_csv
when you pass type = "text/csv"
. You can pass parameters through to read_csv
within content
and luckily read_csv
allows you to define the column types of the csv you're importing.
invoice <- content(getdata, type = "text/csv", col_types = cols(
Account.external_id__c = col_integer(),
Invoice.Amount = col_double(),
Invoice.Balance = col_double(),
Invoice.CreatedDate = col_datetime(format = "")
))
通知 Invoice.Balance = col_double()
.
有关更多信息,请参见 vignette("column-types",package ="readr")
.
See vignette("column-types", package = "readr")
for more info.
这篇关于httr CSV内容读取为整数而不是双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!