Crunch-io / rcrunch

R package for interacting with the Crunch API

Home Page:https://crunch.io/r/crunch/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`setEntitySlot` could be better about avoiding unnecessary `PATCH`es

gergness opened this issue · comments

In investigating #578, I noticed that setting category names to their existing names still results in a PATCH.

httr::with_verbose(categories(ds$test_cat1) <- categories(ds$test_cat1))
#> -> PATCH /api/datasets/8e6c08d6a6d4409fb3b13019d72ca258/variables/d96073d986174f6995611111da436654/ HTTP/2
#> -> Host: app.crunch.io
#> -> Accept-Encoding: deflate, gzip
#> -> Accept: application/json, text/xml, application/xml, */*
#> -> Authorization: Bearer <REDACTED>
#> -> user-agent: libcurl/7.64.1 curl/4.3.2 httr/1.4.2 rcrunch/1.28.1 token
#> -> Content-Length: 241
#> -> 
#> >> {"categories":[{"id":1,"missing":false,"name":"o","numeric_value":1},{"id":2,"missing":false,"name":"p","numeric_value":2},{"id":3,"missing":false,"name":"q","numeric_value":3},{"id":-1,"missing":true,"name":"No Data","numeric_value":null}]}
#> 
#> <- HTTP/2 204 
#> <- date: Wed, 11 Aug 2021 19:05:55 GMT
#> <- location: https://app.crunch.io/api/datasets/8e6c08d6a6d4409fb3b13019d72ca258/variables/d96073d986174f6995611111da436654/
#> <- server: nginx
#> <- allow: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
#> <- vary: Cookie, Accept-Encoding
#> <- x-xss-protection: 1; mode=block
#> <- strict-transport-security: max-age=31536000; includeSubDomains
#> <- x-content-type-options: nosniff
#> <- 

The problem is that when checking if they're the same: https://github.com/Crunch-io/rcrunch/blob/master/R/shoji.R#L72

The value on the VariableEntity is a regular R list but the value argument is a true Categories S4 object. Not sure whether it'd be better to make a new function that does the comparison but adapts the classes for you, or if the VariableEntity could be changed so that it had the actual categories on them.