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

Expand the Update-from-openxlsx vignette to show an example using pipes #561

Closed
Moohan opened this issue Mar 23, 2023 · 2 comments
Closed

Comments

@Moohan
Copy link

Moohan commented Mar 23, 2023

Hopefully it's not just me but I found the example in https://janmarvin.github.io/openxlsx2/articles/Update-from-openxlsx.html very confusing where the functions are chained using $ I'm from a tidyverse background which maybe explains it but I've never seen that kind of code before.

The doc implies that you could write something like

border_color <- wb_color(hex = "FF4F81BD")
wb <- wb_workbook("My name here") |>
  wb_add_worksheet("Expenditure", gridLines = FALSE) |>
  wb_add_data(x = USPersonalExpenditure, rowNames = TRUE) |>
  wb_add_border( # add the outer and inner border
    dims = "A1:F6",
    top_border = "thin", top_color = border_color,
    bottom_border = "thin", bottom_color = border_color,
    inner_hgrid = "thin", inner_hcolor = border_color,
    left_border = "", right_border = ""
  ) |>
  wb_set_col_widths( # set column width
    cols = 1:6,
    widths = c("20", rep("10", 5))
  ) |> # remove the value in A1
  wb_add_data(dims = "A1", x = "")

Which looks much more recognisable to my brain!

Is this the case? If so could the doc be updated to include examples of this style?

@JanMarvin
Copy link
Owner

Hi @Moohan , appreciate the request. Documentation is not our strong side. Guess we can add a few more examples.

@JanMarvin
Copy link
Owner

JanMarvin commented Mar 23, 2023

Generally speaking, whenever you see a chained function (they are more common in Python afaik), you can replace wb$function() with wb <- wb |> wb_function(). All (probably most) chained wbWorkbook functions have a matching wrapper function beginning with wb_. Similar most wb_ functions should be chainable, but there are some cases where we are not (yet) there. Notably wb_load() and wb_to_df() are not wbWorkbook functions (there is no wb$load() and no wb$to_df()) and not every wbWorkbook function is chainable. No rule without exceptions.

Since I haven't looked at openxlsx in a while and since we have written or at least re-written major parts of the package, please let us know where documentation is lacking and if you need further help let us know in a discussion topic.

For a start, most of the man pages for non wrapper functions contain only dummy texts, but let's not talk about this 😄

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

No branches or pull requests

2 participants