This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "data_frame.h" | |
namespace R { | |
// TODO: column names and classes | |
data_frame read_csv(std::string file_path, bool has_header = true); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "r_date.h" | |
#include <iomanip> | |
#include <cassert> | |
#include <algorithm> | |
std::ostream& operator<<(std::ostream& os, const R::r_date& date) { | |
os << std::put_time(&date.tm, date.format.c_str()); | |
return os; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <string> | |
#include <ctime> | |
#include <ostream> | |
namespace R { | |
/** | |
* An R-ish calender date type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <string> | |
namespace R { | |
/** | |
* The 7 R-ish data types: | |
* r_raw, r_integer, r_numeric, r_string, r_logical, r_complex, r_date | |
* converted to tokens with an extra 'broken' token for unrecognized type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read dumb data into heterogeneous container | |
manufacturer model hwy displ year cyl drv cty trans fl class | |
(str) (str) (int) (num) (int) (int) (str) (int) (str) (str) (str) | |
0 audi a4 29 1.8 1999 4 f 18 auto(l5) p compact | |
1 audi a4 29 1.8 1999 4 f 21 manual(m5) p compact | |
2 audi a4 31 2 2008 4 f 20 manual(m6) p compact | |
3 audi a4 30 2 2008 4 f 21 auto(av) p compact | |
4 audi a4 26 2.8 1999 6 f 16 auto(l5) p compact | |
5 audi a4 26 2.8 1999 6 f 18 manual(m5) p compact |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "data_frame.h" | |
#include "read_csv.h" | |
#include "head.h" | |
using namespace R; | |
int main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import the data and look at the first six rows | |
car_data <- read.csv(file = 'data/mpg.csv') | |
head(car_data) | |
manufacturer model hwy displ year cyl drv cty trans fl class | |
(str) (str) (int) (num) (date) (int) (str) (int) (str) (str) (str) | |
1 audi a4 29 1.8 1999 4 f 18 auto(l5) p compact | |
2 audi a4 29 1.8 1999 4 f 21 manual(m5) p compact | |
3 audi a4 31 2 2008 4 f 20 manual(m6) p compact | |
4 audi a4 30 2 2008 4 f 21 auto(av) p compact |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "r_data_frame.h" | |
namespace R { | |
variant_vector as_dates(std::vector<std::string> source) { | |
R::variant_vector tm_dates; | |
for (const auto& date : source) { | |
std::stringstream ss; | |
ss << date + "T00:00:00Z "; | |
std:tm tm; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heterogeneous container | |
id name salary start_date | |
0 1 Rick 623.3 2012-01-01 | |
1 2 Dan 515.2 2013-09-23 | |
2 3 Michelle 611 2014-11-15 | |
3 4 Ryan 729 2014-05-11 | |
4 5 Gary 843.25 2015-03-27 | |
Dan earns $515.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "r_data_frame.h" | |
int main() { | |
std::cout << "heterogeneous container\n\n"; | |
R::data_frame d; |