问题描述
我想使用RSQLite将一堆大文本文件导入到SQLite数据库中.如果我的数据以逗号分隔,则可以执行以下操作:
I'd like to import a bunch of large text files to a SQLite db using RSQLite. If my data were comma delimited, I'd do this:
library(DBI)
library(RSQLite)
db <- dbConnect(SQLite(), dbname = 'my_db.sqlite')
dbWriteTable(conn=db, name='my_table', value='my_file.csv')
但是用'\ t'分隔的数据呢?我知道我可以将数据读取到R data.frame中,然后从中创建表,但是我想直接进入SQLite,因为有很多大文件.当我对数据进行上述尝试时,我得到了一个字符字段.
But how about with '\t' -delimited data? I know I could read the data into an R data.frame and then create the table from that, but I'd like to go straight into SQLite, since there are lots of large files. When I try the above with my data, I get one single character field.
我可以使用sep ='\ t'这样的选项吗?我试过像这样添加sep ='\ t':
Is there a sep='\t' sort of option I can use? I tried just adding sep='\t', like this:
dbWriteTable(conn=db, name='my_table', value='my_file.csv', sep='\t')
实际上,这很好用,但是我正在使用的文件中的缺陷产生了一个错误.如果您像我一样具有标头,也可以添加header = TRUE.
And in fact that works great, but a flaw in the file I was working with was producing an error. Also good to add header=TRUE, if you have headers as I do.
推荐答案
尝试以下操作:
dbWriteTable(conn=db, name='my_table', value='my_file.csv', sep='\t')
根据以下内容, http://的第21页顶部cran.r-project.org/web/packages/RMySQL/RMySQL.pdf
[snip]
sep =指定字段分隔符,默认为','.
sep= specifies the field separator, and its default is ','.
这篇关于如何使用RSQLite将制表符分隔的数据导入sqlite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!