Author

Lyn Howard

Published

July 31, 2024

To enable others to help you, you’ll need to include a reprex, or reproducible example - a minimal example of the data and code you’re using, so they can recreate the problem.

Setting things up

Ctrl + F7 in RStudio will open a new source column which you can use to gather together the information you want to share in your request for help.

You’ll often want to include a sample of your dataframe rather than the whole thing, particularly if it’s very large.

fresh_data <- NHSRdatasets::LOS_model |> dplyr::slice_sample(n = 20) # This produces a sample dataframe of 20 randomly selected rows. slice_sample(prop=0.2) will randomly select 20% of rows

Sharing your data

The base R function dput() produces the code to recreate your data sample.

fresh_data |> dput()

or another alternative is to use df_paste() from the datapasta package.

Editing the dataframe

You may need to edit the data before sharing it to anonymise it or remove confidential information. You could manually edit the output from dput() or df_paste.

An alternative way to modify your data for sharing

# create a dataframe of organisation names and aliases
Organisation <- unique(NHSRdatasets::LOS_model$Organisation)
length(Organisation) # checks the length of the vector Organisation
alias <- letters[1:10] # if you want to automate this you could use letters[1:length(Organisation)]
df <- data.frame(Organisation, alias) # combines the 2 vectors into a dataframe

Join the dataframe we just created to the LOS_model dataframe, select the columns we want & take a sample 10 rows, before piping it into dput() to create the code we can share.

dplyr::left_join(NHSRdatasets::LOS_model, df) |>
  select(Age, alias, Death) |>
  slice_sample(n = 10) |>
  dput()

What should you include?

  • libraries used

  • your code and an explanation of what you’re trying to achieve

  • the smallest dataset that still works

  • error messages

  • what solutions you’ve already tried

  • check that the code you’re sharing works exactly like your original code with the issue. Sometimes you’ll realise for yourself what the solution is at this point!

  • check that the code you’re sharing works exactly like your original code with the issue.

Don’t include:

  • anything confidential

  • any code that isn’t essential to the part you’re asking about

Where can you ask for help?

NHS-R Community Slack forum

The Posit forum, hosted by the company that makes and maintains RStudio

Back to top

Reuse

CC0

Citation

For attribution, please cite this work as:
Howard, Lyn. 2024. “How to Ask for Help.” July 31, 2024. https://nhs-r-community.github.io/nhs-r-community/blog/asking_for_help.html.