Having problem with RSQLite : RStudio

Hi, I’m trying to learn how to use RSQLite but I’m already having a problem, wondered if anyone knows how to fix it.

I have a pre-existing database (.data) file which does not have attribute names and I am trying to create a SQLite database with a table defined with attribute names and data types then copy all of the data from my pre-existing database into this table.

I make the SQLight database with:

db <- dbConnect(SQLite(), dbname = "ExampleDB.sqlite")

Then create a table with: [etc. just shows where I have 53 more]

dbSendQuery(conn = db, "CREATE TABLE IF NOT EXISTS Exampetable (WEIGHT INT, etc.)")

However I believe my issue is with this next part, I first get the data from existing database

mydata <- read.csv('preexistingdatabase.data')

Then I try to add that data to my table in SQLight database with dbWriteTable:

dbWriteTable(conn = db, name = 'Exampetable', value = mydata , append = TRUE, overwrite = FALSE)

Although when I try to run this I get an error which says

Error:Columns 'X140','Not.in.universe',etc. not found

between columns and not found is essentially the first row of the pre-existing database file i’m trying to use but every integer value now has an X in front of it.

As an example of what I’m trying to get in the end, the SQLite file should look like this:

WEIGHT SECTOR etc.
140 Not.in.universe etc.

but I just can’t get my head around why I’m getting an error using dbWriteTable. Any help is appreciated.

Read more here: Source link