Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: line 25 did not have 57 elements #16

Open
liwencong1995 opened this issue Oct 4, 2016 · 2 comments
Open

Error: line 25 did not have 57 elements #16

liwencong1995 opened this issue Oct 4, 2016 · 2 comments

Comments

@liwencong1995
Copy link
Collaborator

This error is caused by the sep parameter.
I still need to figure how to fix it.

> lapply(valid_months$new_lcl, FUN = DBI::dbWriteTable, conn = obj$con, 
+        name = "calls", sep = "|")
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 25 did not have 57 elements
> lapply(valid_months$new_lcl, FUN = DBI::dbWriteTable, conn = obj$con, 
+        name = "calls", sep = "?")
Error in .local(conn, name, value, ...) : 
  RS_sqlite_import: /Users/Priscilla/Desktop/nyc311/load/nyc311_2011_1.csv line 8415 expected 1 columns of data but found 57
> lapply(valid_months$new_lcl, FUN = DBI::dbWriteTable, conn = obj$con, 
+        name = "calls", sep = "~")
[[1]]
[1] TRUE
@liwencong1995
Copy link
Collaborator Author

read_delim {read} might be a solution?

@beanumber
Copy link
Owner

See this: (https://www.sqlite.org/cvstrac/wiki?p=ImportingFiles)

Unfortunately, not all CSV files are simple. For instance, the CSV line

"Last, First", 1234
means two columns in Excel (a name and an integer), but three columns with embedded quote marks in SQLite. Be wary when trying to import CSV files.

Some problems you would encounter importing CSV files using the SQLite shell:

Fields with commas in them. The SQLite shell will always split fields on the separator character, no matter what comes before or after it. Quotes or backslashes won't escape them.
Quoted fields. The SQLite shell will interpret quotes literally, so the imported database will have embedded quote marks in them.
Fields with carriage returns or newlines. The SQLite shell inteprets them as ending the row.
There is no standard as to what a CSV file should look like, and the SQLite shell does not even attempt to handle all the intricacies of interpreting a CSV file. If you need to import a complex CSV file and the SQLite shell doesn't handle it, you may want to try a different front end, such as SQLite Database Browser.

It seems that the problem is not with R, or even RSQLite, but with SQLite itself. It's ability to parse a CSV seems very limited. I guess we can try using a non-standard separator, but we need to pick something that won't appear anywhere in the text fields!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants