Crunch-io / rcrunch

R package for interacting with the Crunch API
https://crunch.io/r/crunch/
GNU Lesser General Public License v3.0
9 stars 15 forks source link

Add weighting / other batteries included to newExampleDataset #443

Closed 1beb closed 4 years ago

1beb commented 4 years ago
> library(crunch); login()
> ds = newExampleDataset()
> weightVariables(ds) 
> NULL

When writing vignettes or creating examples for using R crunch, it would be useful if the example dataset came with a few more batteries included.

We, internally, already have a candidate dataset that is an extension of the current one.

1beb commented 4 years ago

If you could show me how to convert a ds to the json / csv formats you have in https://github.com/Crunch-io/rcrunch/tree/master/inst/example-datasets I would submit a PR for this

malecki commented 4 years ago

@1beb check out the new Schema endpoint — it provides a view of base data (not derivations) consistent with what is accepted in a create-dataset payload. Reminds me we should think about how to expose and interact with that endpoint here.

1beb commented 4 years ago

Ok, this looks about right so far:

toJSON(crGET("https://app.crunch.io/api/datasets/<DATASETID>/schema"))

But how do I generate the csv?

malecki commented 4 years ago

write.csv(as.data.frame(?

gergness commented 4 years ago

There's also exportDataset

1beb commented 4 years ago

The problem I'm having is that the weight variable doesn't appear to come through in the schema.

reprex:

library(crunch)
ds = newExampledataset() 
ds$weight = makeWeight(ds$q1 ~ c(0.75, 0.15, 0.10), name = "weight")
modifyWeightVariables(ds, "weight") # Assign "weight" as the weighting variable
exportDataset(ds, "example-dataset.csv") # has a column called weight as expected
# write.csv(as.data.frame(ds), "examples-dataset.csv") # has weight
toJSON(crGET("https://app.crunch.io/api/datasets/<DATASETID>/schema")) # no weight var

In addition, when trying to use the endpoint provided as the data it fails in createDatasetWithMediaAndData. I spent some time trying to manipulate the JSON result from the endpoint but it still looked different than the initial pets and it wasn't clear why it was being rejected.

1beb commented 4 years ago

Closing for now. Identified API issue where numeric variables output ids at schema end point making automatic round trips of data creation require a lot of munging.