Skip to content

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

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.79%. Comparing base (b9dfe78) to head (1a9fd6f).
Report is 87 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@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?

@monkeywithacupcake
Copy link
Contributor Author

monkeywithacupcake commented Feb 9, 2025

hello @renkun-ken or @krlmlr - any chance of a merge? this is old, but looks like it still does not conflict with base

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