nhs-r-community / NHSRplotthedots

An SPC package to support NHSE/I 'Making Data Count' programme
https://nhs-r-community.github.io/NHSRplotthedots/
Other
48 stars 23 forks source link

"value" section of ptd_spc is incorrect #129

Closed tomjemmett closed 2 years ago

tomjemmett commented 3 years ago

ptd_spc documentation suggests that this function returns a ggplot object - it does not. The plot/ptd_create_ggplot do return ggplot objects, but ptd_spc returns a c("ptd_spc_df", "tbl_df", "tbl", "data.frame"). Need to update the documentation

ThomUK commented 3 years ago

One confusion is that if you run ptd_spc() without assigning the result, it does return a plot. If you run result <- ptd_spc() you get a dataframe. Is there an accepted way to describe that behaviour that could be included in the docs?

tomjemmett commented 3 years ago

Strictly speaking, ptd_spc() never returns a plot. It always returns a data.frame derived object.

In an interactive session running this function in a console calls the print() method. This method in turn calls plot().

This is the pretty much the same behaviour as ggplot - if you run in the console and don't assign it immediately calls the underlying plotting method from print().

I'll have a look to see how it's described there and borrow any useful wordings.

ThomUK commented 3 years ago

Gotcha, that makes sense. I never realised that there were things going on outside of the package that caused that behaviour.

tomjemmett commented 3 years ago

I've started to work on this in #137, but would value some other pairs of eyes to have a look and come up with some better description of what this function returns.