The sqldf::read.csv.sql()
function has been useful retrieving only a small portion of a large CSV.
However, the connection remains open and eventually produces the following warnings (after running it a few times):
Warning messages:
closing unused connection 11 (C:\Users\wibeasley\AppData\Local\Temp\asfasdf\fileasdfasdfasdf)
Four years ago, it was recommended to issue
base::closeAllConnections()
.
Is there a newer way to selectively close only the connection created by sqldf::read.csv.sql()
?
path <- tempfile()
write.csv(mtcars, file=path, row.names=F)
# read.csv(path)
ds <- sqldf::read.csv.sql(path, "SELECT * FROM file", eol="\n")
base::closeAllConnections() # I'd like to be more selective than 'All'.
unlink(path)
The real code is the middle two lines. The first three lines set up the pretend file. The final base::unlink()
deletes the temp CSV.
My attempts to pass an existing file connection (so I can later explicitly close it) apparently still leave the connection open when I run it several times:
Warning messages:
1: In .Internal(sys.call(which)) : closing unused connection 13 ()
path <- tempfile()
write.csv(mtcars, file=path, row.names=F)
ff <- base::file(path) # Create an explicit connection.
ds <- sqldf::read.csv.sql(sql="SELECT * FROM ff")
base::close(ff)
unlink(path)