Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

7 anos atrás
7 anos atrás
7 anos atrás
7 anos atrás
7 anos atrás
7 anos atrás
7 anos atrás
7 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # tidyflow: a workflow that fits the tidyverse
  2. Tidyflow is *not* a package, but a project skeleton that you can clone/fork to start your own projects.
  3. It follows the project structure proposed by Hadley Wickham in [R for Data Science](http://r4ds.had.co.nz/)
  4. ![](http://r4ds.had.co.nz/diagrams/data-science.png)
  5. *Image under [CC-BY-NC-ND](https://creativecommons.org/licenses/by-nc-nd/3.0/us/)*
  6. ## Install
  7. If you are on github, simply fork the repo.
  8. If you don't want to use github as your remote, clone the depo in a new directory
  9. `git clone https://www.github.com/maximewack/tidyflow new_project`
  10. Then change the git remote origin to your own remote repo.
  11. `git remote set-url your_repo_url`
  12. The project already contains a *.gitignore* file for R projects.
  13. Add rules for your data files if you don't want them to be shared.
  14. Also run `install.packages(c("tidyverse", "rmarkdown", "knitr"))` to install the necessary dependencies.
  15. ## Directory structure
  16. The project contains three subdirectories: **Data/**, **Docs/** and **Rmd/**.
  17. **Data/** also contains a **Raw/** subdirectory.
  18. **Data/Raw/** should contain the raw data when they exist as files (csv, xls(x), SQLite databases, SAS files, SPSS files, etc.).
  19. **Docs/** should contain all external documents you have about the project (synopsis, context articles/presentations, etc.)
  20. **Rmd/** will contain the files used to communicate the results.
  21. ## Scripts
  22. Four scripts are already present, populated with boilerplate code for each of the steps.
  23. Packages `dplyr`, `magrittr`, `tidyr`, and `purrr` can be useful all the way.
  24. **Every step makes a "savepoint" of your work, allowing you to rapidly iterate on any of the steps without having to re-run the previous ones (unless you've changed something up in the chain).**
  25. ### 01_Import.R
  26. The first script is used to import raw data (whatever the source) and save a local csv copy in **Data/**.
  27. Useful packages from the tidyverse here are `readr`, `readxl`, `rvest`, `haven`, and `jsonlite`.
  28. Having the data ready as simple csv is useful to always be able to start from the beginning, even if the original source is unavailable.
  29. ### 02_Tidy.R
  30. This step consists mostly of "non-destructive" data management: assign types to columns (factors with correct/human readable levels, dates, etc.), correct/censor obviously abnormal values and errors), transform between *long* and *wide* format, etc.
  31. Useful packages here are `lubridate`, `stringr`, and `forcats`.
  32. The results are saved in a **tidy.Rdata** file.
  33. After this second step, you will have your full data ready to use in R and shouldn't have to run the first two steps anymore (unless you get hold of new data).
  34. ### 03_Transform.R
  35. This script is for data transforming. It will contain all transformations of the data to make them ready for analyses.
  36. Some "destructive" data management can occur here, such as dropping variables or observations, or modifying the levels of some factors.
  37. Useful packages here are `forcats`, `lubridate`, and `stringr`.
  38. The results are saved in a **transformed.Rdata** file.
  39. ### 04_Analyze.R
  40. This script will contain more data transforming, and the analyses with production of the resulting tables and plots.
  41. There is a bit of an overlap between **03_Transform.R** and **04_Analyze.R** as it is often an iterative process. Both files can be merged into one, but it can be useful to have some time-consuming transformations in a separate script and have the results handy.
  42. Useful packages here are `broom`, `ggplot2`, and `modelr`.
  43. In this script *all* the "interesting results," full tables and ggplot graphs are included in a single hierarchical list, saved in a **results.Rdata** file.
  44. All the results from the analyses should be saved as-is without transformation, so that every result can be used in the Rmd.
  45. Having all the results pre-computed for the Rmd means that it will take mere seconds to re-compile, while still having access to all the results if you want/need to use them somewhere in the manuscript/report.
  46. The results object can look like this:
  47. ```
  48. results
  49. ├─ tables
  50. │ ├─ demographics
  51. │ ├─ ttt_vs_control
  52. │ └─ table3
  53. ├─ list_of_interesting_values
  54. ├─ interesting_values2
  55. └─ plots
  56. ├─ figure1
  57. ├─ figure2
  58. └─ figure3
  59. ```
  60. ### Rmd/report.Rmd
  61. The Rmd file should not contain *any* literal values: every number, table, graph *has* to come from the results object (in its original form).
  62. Only some really minor cosmetic modifications should be made then (running `prettyNum` on numerics or table columns, `select`/`filter`/`arrange`/`rename` on the full tables, etc.)
  63. Multiple Rmds can be made using the same results: one for a full blown scientific article, one for a quick report, one for a presentation, etc.
  64. You will never have to check again for discrepancies between tables/figures and text, or even between different media.