问题
I have created an R function to perform subsetting, summaries, densities, and plotting. I was initially assigning out the subsets to my workspace in RStudio but I started running into memory constraints. The latest revision is attempting to store the summarized observation counts in a SQLite database vs. exporting the subsets as their own dataframes. The theory was that this would utilize less memory. In order to perform this process I created a new database in my function as in:
sqldf("attach 'mydb' as new")
sqldf("create table TotalsTbl as select 'resimrr' as name, count(*) as count from resimrr", dbname="mydb")
sqldf("insert into TotalsTbl select 'resimrrquan' as name, count(*) as count from resimrrquan", dbname="mydb")
I then create a few tables, and populate them as the function processes. Finally I export the query results of SQLite Tables to dataframes that I then assign out to my workspace.
This provides the expected result:
sqldf("select * from TotalsTbl, dbname="mydb")
name count
1 resimrr 95517
2 resimrrquan 93928
The challenge now is that the database is persistent. It is created the first time the function is envoked, it lives in my Rsessions and my workspace and if I run the function again the CREATE TABLE commands fail because the tables already exist. So the question is how do I delete/clean up 'mydb' after I am through with it in my function?
来源:https://stackoverflow.com/questions/16593364/how-do-you-explicitly-delete-a-sqlite-database-created-with-the-sqldf-library-in