`The sketch path is not set.` error when loading table in global

I have a large 500K row table that I am trying to use for animating a point. All the examples I can find for loadTable() show the table loading in draw() and using a for loop there to iterate over rows. What I want to do is load the table once, then call rows by index. This code, where I try to load the table in global scope, is giving me a The sketch path is not set. error. When I put the loadTable() call in draw() it works, but is slow, or at least seems slow.

Is there a reason why when loadTable() is called in the global scope I am getting this error?

int rowCnt = 0;

void setup()
{
  size(200, 200);
  smooth();
  frameRate(1000);
}

Table table = loadTable("data/bd.csv", "header");

void draw()
{
  background(255, 255, 255);
  TableRow row = table.getRow(rowCnt);
  int cnt = row.getInt("bike_count");
  ellipse(100, 20 + cnt, 10, 10);
  rowCnt += 1;
}

1 Like

Problem is this line:

Table table = loadTable("data/bd.csv", "header");

instead:

Table table; outside setup ()

AND

The loading inside setup() after size()

Chrisir

1 Like

also your program flow in the draw loop would show?
one row per frame until error end of table

pls start from here:

// simple CSV read to spreadsheet
Table data;
String data_fn = "data/bd.csv";
int dc = 60, dx = 10, dr =20, posx, posy;

void setup() {
  size(500, 500);
  data = loadTable(data_fn, "header");
}

void draw() {
  background(80, 80, 0);
  for (int c =0; c < data.getColumnCount(); c++)     text(data.getColumnTitle(c), dx+c*dc, dr);     // data Column Header
  
  for (int r = 0; r < data.getRowCount(); r++)   for (int c =0; c < data.getColumnCount(); c++) {   // data
    posx = dx+c*dc;      
    posy = (r+1)*dr;
    text(data.getString(r, c), posx, dr + posy);                                                    // data cell content
  }
}

//data/bd.csv
/*
town,bike_count
here,234
there,567
nowhere,0
*/

1 Like

Great, thank you both. I was struggling with how scope the Table object. Here is the final working sketch:

Table data;
int rowCnt = 0;

void setup() {
  size(200, 200);
  frameRate(10);
  data = loadTable("data/bd.csv", "header");
}

void draw() {
  background(255, 255, 255);
  TableRow row = data.getRow(rowCnt);
  int cnt = row.getInt("bike_count");
  ellipse(100, 20 + cnt, 10, 10);
  rowCnt += 1;
}

A remaining question I have is, why can’t the Table object be assigned in the header, as rowCnt is?

1 Like

B/c all Processing’s loading functions depend on PApplet::sketchPath to be already initialized: :open_file_folder:

The loading must be after size() command to work