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
Add S3-method based formatting #22
Conversation
@bobjansen -- so sorry for the long delay with my reply here :( So I was not sure how to do this properly and played around a little bit trying to figure out how to be able to pass parameters to This way we do not need the extra S3 step as Please see the just pushed commit and let me know what you think. On the other hand, do you want to pass multiple objects to the same |
Codecov Report
@@ Coverage Diff @@
## master #22 +/- ##
========================================
- Coverage 72.89% 72.5% -0.4%
========================================
Files 11 11
Lines 369 371 +2
========================================
Hits 269 269
- Misses 100 102 +2
Continue to review full report at Codecov.
|
Example run: > log_formatter(formatter_pander)
> log_info('42')
INFO [2019-07-25 09:31:34] 42
> log_info(40 + 2)
INFO [2019-07-25 09:31:37] _42_
> log_info(head(iris))
INFO [2019-07-25 09:31:41]
INFO [2019-07-25 09:31:41] -------------------------------------------------------------------
INFO [2019-07-25 09:31:41] Sepal.Length Sepal.Width Petal.Length Petal.Width Species
INFO [2019-07-25 09:31:41] -------------- ------------- -------------- ------------- ---------
INFO [2019-07-25 09:31:41] 5.1 3.5 1.4 0.2 setosa
INFO [2019-07-25 09:31:41]
INFO [2019-07-25 09:31:41] 4.9 3 1.4 0.2 setosa
INFO [2019-07-25 09:31:41]
INFO [2019-07-25 09:31:41] 4.7 3.2 1.3 0.2 setosa
INFO [2019-07-25 09:31:41]
INFO [2019-07-25 09:31:41] 4.6 3.1 1.5 0.2 setosa
INFO [2019-07-25 09:31:41]
INFO [2019-07-25 09:31:41] 5 3.6 1.4 0.2 setosa
INFO [2019-07-25 09:31:41]
INFO [2019-07-25 09:31:41] 5.4 3.9 1.7 0.4 setosa
INFO [2019-07-25 09:31:41] -------------------------------------------------------------------
INFO [2019-07-25 09:31:41]
> log_info(head(iris), style = 'simple')
INFO [2019-07-25 09:31:43]
INFO [2019-07-25 09:31:43]
INFO [2019-07-25 09:31:43] Sepal.Length Sepal.Width Petal.Length Petal.Width Species
INFO [2019-07-25 09:31:43] -------------- ------------- -------------- ------------- ---------
INFO [2019-07-25 09:31:43] 5.1 3.5 1.4 0.2 setosa
INFO [2019-07-25 09:31:43] 4.9 3 1.4 0.2 setosa
INFO [2019-07-25 09:31:43] 4.7 3.2 1.3 0.2 setosa
INFO [2019-07-25 09:31:43] 4.6 3.1 1.5 0.2 setosa
INFO [2019-07-25 09:31:43] 5 3.6 1.4 0.2 setosa
INFO [2019-07-25 09:31:43] 5.4 3.9 1.7 0.4 setosa
INFO [2019-07-25 09:31:43]
> log_info(lm(hp ~ wt, mtcars))
INFO [2019-07-25 09:31:46]
INFO [2019-07-25 09:31:46] ----------------------------------------------------------------
INFO [2019-07-25 09:31:46] Estimate Std. Error t value Pr(>|t|)
INFO [2019-07-25 09:31:46] ----------------- ---------- ------------ ---------- -----------
INFO [2019-07-25 09:31:46] **(Intercept)** -1.821 32.32 -0.05633 0.9555
INFO [2019-07-25 09:31:46]
INFO [2019-07-25 09:31:46] **wt** 46.16 9.625 4.796 4.146e-05
INFO [2019-07-25 09:31:46] ----------------------------------------------------------------
INFO [2019-07-25 09:31:46]
INFO [2019-07-25 09:31:46] Table: Fitting linear model: hp ~ wt
INFO [2019-07-25 09:31:46] |
Apologies for taking so long, this looks good! I've rebased the commits into one. To your question: I don't think I would want to log multiple objects at once. |
Thanks for this! Do you have any plans for an update of the package on CRAN? |
Yeah, I'm waiting for my |
See also #40 |
This would allow definition of formatting methods per S3-class. As a proof of concept, I've added pander to do this as done in your SO answer.