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 7438467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:33:32+00:00 2026-05-29T10:33:32+00:00

I have a script that works fine when I run it manually in R

  • 0

I have a script that works fine when I run it manually in R Studio, but does not work when I run it from another program through a wrapper.

I get this info in my debug output:

[912] Error in xj[i] : only 0's may be mixed with negative subscripts 
[912] Calls: GetTopN -> cor -> is.data.frame -> [ -> [.data.frame 

If I save the image right before I get the error and then load it in R Studio I get the same error when I execute GetTopN(10). However, if I re-run the statement actionlist<- sqlQuery(channel,al_string) within R Studio and then execute GetTopN(10) everything works as it should.

I even tried to save the image within R Studio right before the critical call, and then load it through the wrapper before executing GetTopN(10) and I got the same error.

I checked and all of the relevant variables (crs,z,x,n) appear to have the proper values. I have no idea what could be the cause of this, and I’d really appreciate some help!

Here is what is being executed (in order):

#INIT:
library(RODBC)
library(stats)

channel<- odbcConnect("data")
crs<-mat.or.vec(3000,5) #will hold correlations
n1<-seq(-33,0)

#Get whole series
z <- sqlQuery(channel,"SELECT RPos,M1,M2,M3,M4 FROM `data`.`z` ")
al_string <- "SELECT RPos,OpenTime FROM z JOIN actionlist on(OpenTime = pTime)"
trim_string<- "DELETE FROM ActionList WHERE OpenTime NOT IN (SELECT OpenTime FROM ReducedList)"

GetTopN<-function(n)
{ 
  for(i in 1:nrow(actionlist))
  {
   crs[i,1]<-actionlist$OpenTime[i]
   for(j in 2:ncol(z)) 
   {
    crs[i,j]<-cor(z[actionlist$RPos[i]+n1,j],x[,j])
   }
  }
  avc <- (cbind(crs[,1],rowSums(crs[,2:5])))
  sorted <- crs[order(avc[,2], decreasing=T),1] 
  topx<- head(sorted,n)
  bottomx <- tail(sorted,n)
  DF<-as.data.frame(c(topx,bottomx),row.names=NULL) 
  colnames(DF)[1]<-'OpenTime'
  sqlSave(channel,dat=DF,tablename='ReducedList',append=F,rownames=F,safer=F) 
  sqlQuery(channel,trim_string)
}


curpTime <- 1275266400
actionlist<- sqlQuery(channel,al_string)

x<- sqlQuery(channel,paste('SELECT pTime,M1,M2,M3,M4 FROM z WHERE pTime <= ',curpTime,' AND 
pTime > ',curpTime,'-(300*34) ORDER BY pTime ASC'))

GetTopN(10)

I saved my workspace too if it might help (4.7mb): workspace
If connecting to my MYSQL database would help, it should be open on 74.73.17.163:3306

  • 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-29T10:33:33+00:00Added an answer on May 29, 2026 at 10:33 am

    The problem: actionlist$RPos[1000] has a value of 21. n1 ranges from -31 to 0. When you add them you get a vector with a mix of positive and negative values, which isn’t allowed in subsetting.

    How I got there: First check traceback():

    traceback()
    5: `[.data.frame`(z, actionlist$RPos[i] + n1, j) at #8
    4: z[actionlist$RPos[i] + n1, j] at #8
    3: is.data.frame(x) at #8
    2: cor(z[actionlist$RPos[i] + n1, j], x[, j]) at #8
    1: GetTopN(10)
    

    This tells me the problem is in actionlist$RPos[i] + n1 most likely. Then I just added a simple print(i) statement to tell me which iteration was the problem. (Alternatively, you could probably have just checked actionlist$RPos + n1 for trouble spots manually.

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

Sidebar

Related Questions

I have python script that works fine but only when run as stand-alone, while
I have a java script code that works fine when run through a browser,
I have a script that seemed to work before but no longer does. It
Good Morning, I have a really simple script that works fine on everything but
I have a script that works fine on my test server (using IIS6). The
I have the following code that works fine in IE: <HTML> <BODY> <script language=JavaScript>
With help from you guys I now have a script that works like a
I have the following script that works well in Firefox and Chrome (not sure
Does anyone have an example of script that can work reliably well across IE/Firefox
I have written a jQuery image resize script that works fine when the images

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.