loadTable()
Input / FilesDescription
Loads a CSV or TSV file into a Table object.
Syntax
Table* loadTable(std::string path, std::string options)
Parameters
| Name | Type | Description |
|---|---|---|
| path | std::string | path to the file |
| options | std::string | "header" to treat first row as column names |
Returns
Table*Related
Under the Hood
From Processing.h:
static Table* loadTable(const std::string& path, const std::string& options="header");
Under the Hood
From Processing.cpp:
Table* PApplet::loadTable(const std::string& path,const std::string& options){
Table* t=new Table();
bool hasHeader=options.find("header")!=std::string::npos;
char delim=path.find(".tsv")!=std::string::npos?'\t':',';
auto lines=loadStrings(path);
if(lines.empty())return t;
int start=0;
if(hasHeader){
auto cols=split(lines[0],delim);
for(auto& c:cols)t->addColumn(c);
start=1;
}
for(int i=start;i<(int)lines.size();i++){
auto& row=t->addRow();
auto cells=split(lines[i],delim);
for(int j=0;j<(int)cells.size()&&j<(int)row.size();j++)row[j]=cells[j];
}
return t;
}