0

I have a question about using the paste function and getwd function, my function is:

HTML_OUTPUT_ITERATIONS<-function(df_power_values, df_on_time_values, inventory_DF_List_on_time, DF_inventory_items){
      require(R2HTML)
      x<-1
      DIRECTORY<-getwd()
      FOLDER<-"/outputs"
      OUTPUTS<-paste(DIRECTORY,FOLDER,sep="")
      PATH_OUTPUTS<-gsub(" ","", OUTPUTS, fixed=TRUE)
      HTMLStart(outdir=PATH_OUTPUTS, file="iterations",extension="html", echo=FALSE, HTMLframe=TRUE)
      HTML.title("Iterations Log Report", HR=3)
      HTMLhr()
      HTML.title("Log results of iterations powers sequence", HR=2)
      HTMLhr()
      while(x<=length(inventory_DF_List)){
      HTML.title("Power:")
          HTML(df_power_values[x,1], digits=4)
        HTML.title("Inventory:")
          HTML(inventory_DF_List[x])
        x<-x+1
      }
      HTMLhr()
      HTML.title("Log results of iterations Time On sequence", HR=2)
      HTMLhr()
      while(x<=length(inventory_DF_List_on_time)){
        HTML.title("Power:")
          HTML(df_on_time_values[x,1], digits=4)
        HTML.title("Inventory:")
          HTML(inventory_DF_List_on_time[x])
        x<-x+1
      }
      HTMLhr()
      HTMLStop()
    }

As you can see I'm using the library R2HTML. I've been debugging the code and I have not seen any fault, but I'm a very rare mistake. I think the mistake comes from the paste function, but not sure. I think the error is in this part of the code:

          DIRECTORY<-getwd()
          FOLDER<-"/outputs"
          OUTPUTS<-paste(DIRECTORY,FOLDER,sep="")
          PATH_OUTPUTS<-gsub(" ","", OUTPUTS, fixed=TRUE)

I'm using this code to get the path of the folder where the R project, and then add the outputs folder to save it the html report file

the error I get is as follows:

Error in rep(paste("\n\t\t<th>", if (sortableDF) "<b class=\"tablesort\">",  : 
  invalid 'times' argument
Alex
  • 151
  • 13
  • 2
    the `paste()` command seems like an unlikely candidate for the error given the message provided. After you get the error, run `traceback()` and add the results to your question so we can see which function is actually generating the error. – MrFlick May 13 '14 at 18:17
  • also: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Ben Bolker May 13 '14 at 20:57

1 Answers1

0

I've got the solution, the problem was the function that prints HTML data.frames, R2HTML the library. In the case of finding an empty data.frame, fails. I've solved if you print a "EMPTY" should find a position of the empty list :)

HTML_OUTPUT_ITERATIONS<-function(df_power_values, df_on_time_values, inventory_DF_List_on_time, DF_inventory_items){
  require(R2HTML)
  x<-1
  h<-1
  DIRECTORY<-getwd()
  FOLDER<-"/outputs"
  OUTPUTS<-paste(DIRECTORY,FOLDER,sep="")
  PATH_OUTPUTS<-gsub(" ","", OUTPUTS, fixed=TRUE)
  HTMLStart(outdir=PATH_OUTPUTS, file="iterations",extension="html", echo=FALSE, HTMLframe=TRUE)
  HTML.title("Iterations Log Report", HR=1)
  HTMLhr()
  HTMLhr()
  HTML.title("Log results of iterations powers sequence", HR=1)
  HTMLhr()
  while(x<=length(inventory_DF_List)){
  HTML.title("Power:")
      HTML(df_power_values[x,1], digits=4)
    HTML.title("Inventory:")
      HTML(inventory_DF_List[x])
    x<-x+1
  }
  HTMLhr()
  HTML.title("Log results of iterations Time On sequence", HR=1)
  HTMLhr()
  while(h<=nrow(df_on_time_values)){
    HTML.title("On Time value:")
      HTML(df_on_time_values[h,1], digits=4)
    HTML.title("Inventory:")
    if(nrow(as.data.frame(inventory_DF_List_on_time[h]))>0){
      HTML(inventory_DF_List_on_time[h])
    }else{
      HTML.title("EMPTY")
    }
    h<-h+1
  }
  HTMLhr()
  HTMLStop()
}
Alex
  • 151
  • 13