Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6940841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:48:18+00:00 2026-05-27T12:48:18+00:00

My R script has to do a lot of Excel open/write/close/open/read/close, with things in

  • 0

My R script has to do a lot of Excel open/write/close/open/read/close, with things in the middle, and I use for that the RODBC package. There seems to be an issue with odbcCloseAll which won’t close opened Excel connections after a number of times.
Simple example (hopefully reproducible and not just because my PC is weird):

require(RODBC)
filename <- tempfile(fileext='.xls')
for(i in 1:100) {
xlsFile <- odbcConnectExcel(filename, readOnly=FALSE)
sqlSave(xlsFile, USArrests, rownames = FALSE)
odbcCloseAll()
xlsFile <- odbcConnectExcel(filename, readOnly=FALSE)
template <- sqlFetch(xlsFile, "USArrests")
odbcCloseAll()
file.remove(filename)
}

And at some point (around i = 50 in my case), the loop crashes with:

Error in sqlSave(xlsFile, USArrests, rownames = FALSE) : 
  table ‘USArrests’ already exists
In addition: Warning message:
In file.remove(filename) :
  cannot remove file 'c:\DOCUME~1\user\LOCALS~1\Temp\RtmpSFDDiG\file43522f58.xls', reason 'Permission denied'

The problem can easily be solved using odbcClose(xlsFile), or any other package linking to Excel, but for the sake of correctness, I’m wondering what is wrong with odbcCloseAll…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:48:19+00:00Added an answer on May 27, 2026 at 12:48 pm

    Found it, in the C source, there is an error in the C code:

     SEXP RODBCCloseAll(void)
     {
         int i;
    
         for(i = 1; i <= my_min(nChannels, 100); i++) <<<===== error
            if(opened_handles[i])
                      inRODBCClose(opened_handles[i]);
    
         return R_NilValue;
     }
    

    should be

     SEXP RODBCCloseAll(void)
     {
         int i;
    
         for(i = 1; i <= my_min(nChannels, 1000); i++) <<<=====
            if(opened_handles[i])
                  inRODBCClose(opened_handles[i]);
    
         return R_NilValue;
     }
    

    I’ll email the developer. In the mean time you can rebuild the package with this change.
    The error is on line 1235.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a news rating script for this website that has a lot of
EDIT: regulus6633 has made a script that's a lot better than my outline below,
I'm working on a site that still has a lot of scripts in ColdFusion.
I have a script that has PHP on it, and a link that goes
I have A Script that has a Select statement to go to multiple sub
I have a python script that has to launch a shell command for every
I'm writing a script that has to move some file around, but unfortunately it
I have an Excel worksheet that has 30k+ rows. I'd like to cut the
I am modifying some code that has a lot of jQuery but I am
I have a large text file that has a lot of special characters in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.