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

  • Home
  • SEARCH
  • 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 906481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:23:46+00:00 2026-05-15T16:23:46+00:00

Good afternoon, After computing a rather large vector (a bit shorter than 2^20 elements),

  • 0

Good afternoon,

After computing a rather large vector (a bit shorter than 2^20 elements), I have to store the result in a database.

The script takes about 4 hours to execute with a simple code such as :

#Do the processing
myVector<-processData(myData)
#Sends every thing to the database
lapply(myVector,sendToDB)

What do you think is the most efficient way to do this?

I thought about using the same query to insert multiple records (multiple inserts) but it simply comes back to “chucking” the data.

Is there any vectorized function do send that into a database?

Interestingly, the code takes a huge amount of time before starting to process the first element of the vector. That is, if I place a browser() call inside sendToDB, it takes 20 minutes before it is reached for the first time (and I mean 20 minutes without taking into account the previous line processing the data). So I was wondering what R was doing during this time?

Is there another way to do such operation in R that I might have missed (parallel processing maybe?)

Thanks!

PS: here is a skelleton of the sendToDB function:

sendToDB<-function(id,data) {
  channel<-odbcChannel(...)
  query<-paste("INSERT INTO history VALUE(",id,",\"",data,"\")",sep="")
  sqlQuery(channel,query)
  odbcClose(channel)
}

That’s the idea.

UPDATE

I am at the moment trying out the LOAD DATA INFILE command.

I still have no idea why it takes so long to reach the internal function of the lapply for the first time.

SOLUTION

LOAD DATA INFILE is indeed much quicker. Writing into a file line by line using write is affordable and write.table is even quicker.

The overhead I was experiencing for lapply was coming from the fact that I was looping over POSIXct objects. It is much quicker to use seq(along.with=myVector) and then process the data from within the loop.

  • 1 1 Answer
  • 3 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-15T16:23:47+00:00Added an answer on May 15, 2026 at 4:23 pm

    What about writing it to some file and call LOAD DATA INFILE? This should at least give a benchmark. BTW: What kind of DBMS do you use?

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

Sidebar

Related Questions

Good Afternoon, I have a html aspx page that has many many div elements.
Good afternoon, I'm having serious troubles getting my database back up and running. I
Good Afternoon all , I have downloaded data from a web service and im
Good afternoon, I have a quick 'top level' question regarding the usage of Facebook
Good Afternoon All, I have a wizard control that contains 20 textboxes for part
Good afternoon to all, I have this scenario: I am using SQL Server 'BulkInsert'
Good afternoon I have a table that has customer id, name, computer, laptop, blah,
Good Afternoon, I have a Joomla! template that keeps throwing up a pop up
Good afternoon all, I have an instance of a javax.swing.JFileChooser and I added a
Good afternoon people's I have built a jquery plugin that I use on my

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.