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

adds ptype2 and cast support for vctrs #180

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

monkeywithacupcake
Copy link
Contributor

Following directions on vctrs issue 1730, I used the vctrs FAQ to implement self-self comparison in the formattable.R

This adds a dependency import of vctrs ptype2 and cast.

Previously, this would fail the vctrs check

> vctrs::vec_ptype2(currency(1:5),currency(6:10))
Error:
! Can't combine `currency(1:5)` <formattable> and `currency(6:10)` <formattable>.
✖ Some attributes are incompatible.
ℹ The author of the class should implement vctrs methods.
ℹ See <https://vctrs.r-lib.org/reference/faq-error-incompatible-attributes.html>.
Run `rlang::last_error()` to see where the error occurred.

Now, it works

> vctrs::vec_ptype2(currency(1:5),currency(6:10))
formattable integer(0)

This allows pivot longer from currency formatted items (and other tidyr functions that check for compatibility).

However, there are some implications because the class of object is formattable and not, say currency or comma
If you do something that might be erroneous, like make a vector that combines currency and comma, it will mutate both to the attributes of the first

vctrs::vec_ptype2(currency(1:5),comma(6:10))
# formattable integer(0)
vctrs::vec_c(currency(1:5),comma(6:10))
#  [1] $1.00  $2.00  $3.00  $4.00  $5.00  $6.00  $7.00  $8.00  $9.00  $10.00
vctrs::vec_c(comma(1:5),currency(6:10))
#  [1] 1.00  2.00  3.00  4.00  5.00  6.00  7.00  8.00  9.00  10.00

Closes #155

@monkeywithacupcake
Copy link
Contributor Author

Flare

I don't understand the smoke test failure. Obviously works-on-my-machine is not good enough here.

Would need advice on how to correct.

@monkeywithacupcake
Copy link
Contributor Author

I think I figured it out. I had used usethis() when I added the import call, and it created an extraneous formattable_package.R file in the R folder

@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2022

Codecov Report

Merging #180 (1a9fd6f) into master (b9dfe78) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #180      +/-   ##
==========================================
+ Coverage   95.77%   95.79%   +0.01%     
==========================================
  Files          17       17              
  Lines         450      452       +2     
==========================================
+ Hits          431      433       +2     
  Misses         19       19              
Impacted Files Coverage Δ
R/formattable.R 97.02% <100.00%> (+0.03%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@monkeywithacupcake
Copy link
Contributor Author

trying again by adding test coverage.

Now that I think about it...should probably decide how should handle casting of vectors with integer and double - should they be cast as formattable?

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.

Feature Request - Implement vctrs methods to support tidyr
2 participants