Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: parse_deparsed implementation #429

Closed
wants to merge 1 commit into from

Conversation

jimhester
Copy link
Collaborator

@jimhester jimhester commented Jun 9, 2016

Would address #303

I still need to do the deparsing when writing to a file, but wanted to get any comments about this end first, it seems to work well. I am not sure if missing values should return NULL or NA, thoughts?

deparse2 <- function(x) paste(collapse = "", deparse(x))
parse_deparsed(c(deparse2(head(mtcars)), deparse2(head(iris))))
#> [[1]]
#>                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
#> Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
#> Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
#> Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
#> Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
#> Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
#> Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
#> 
#> [[2]]
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1          5.1         3.5          1.4         0.2  setosa
#> 2          4.9         3.0          1.4         0.2  setosa
#> 3          4.7         3.2          1.3         0.2  setosa
#> 4          4.6         3.1          1.5         0.2  setosa
#> 5          5.0         3.6          1.4         0.2  setosa
#> 6          5.4         3.9          1.7         0.4  setosa

SET_VECTOR_ELT(column_, i, ans);
} else {
// parse error
Rcpp::stop("Invalid expression %s", c);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a "problem" rather than terminating parsing of the whole file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agreed I wasn't exactly sure how to do that, but I see there is a warn() function to do it.

@jimhester
Copy link
Collaborator Author

Are you aware of any exported function to do deparsing?

Rf_deparse1line() is what would be best, but it doesn't look like it is part of the API :(

@hadley
Copy link
Member

hadley commented Jun 9, 2016

I was thinking SEXP R_Unserialize(R_inpstream_t ips) but you'd probably need to do a bit of digging to figure out what ips is supposed to be. It's probably a connection? But implementing that is probably overkill.

I just thinking evaluating code from a csv file (even if you've opted in to this) is sufficiently surprising/scary that it basically kills this idea.

@jimhester
Copy link
Collaborator Author

Ok I will table it then, we can always re-open in the future if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants