• Cos’è pigR?
    • Cos’è questo libro.
    • Di cosa hai bisogno per leggere (e capire) questo libro.
    • Chi siamo noi (noi, noi)?
    • Se ti piace…
    • Caveat
    • Cookies
    • La foto di copertina.
    • I cambiamenti in questa edizione.
  • 1 Introduzione
    • 1.1 Cosa c’è da imparare in questo capitolo.
    • 1.2 Convenzioni e guida alla lettura e all’uso del codice.
    • 1.3 Tutti vogliono imparare a usare R.
      • 1.3.1 Provare per credere: App, GUI, IDE e altre diavolerie.
    • 1.4 L’altra faccia della medaglia: troppa fatica.
    • 1.5 R, per pigri.
  • 2 Interfacce e ambienti
    • 2.1 Cosa c’è da imparare in questo capitolo.
    • 2.2 RStudio.
      • 2.2.1 L’interfaccia principale di RStudio.
      • 2.2.2 Il pannello Source.
      • 2.2.3 Il pannello Console.
      • 2.2.4 Il pannello Environment.
      • 2.2.5 Il tab Environment.
      • 2.2.6 Il tab History.
      • 2.2.7 Il pannello Plots.
      • 2.2.8 Il tab Plots.
      • 2.2.9 Il tab Files.
      • 2.2.10 Il tab Packages.
      • 2.2.11 Il tab Help.
    • 2.3 Esercizi.
    • 2.4 Altre risorse.
      • 2.4.1 Risorse in italiano.
      • 2.4.2 Risorse in inglese.
  • 3 Chiedere aiuto
    • 3.1 Cosa c’è da imparare in questo capitolo.
      • 3.1.1 Premessa 1: nessuno legge i manuali (figuriamoci i pigRi)!
      • 3.1.2 Premessa 2: ci sono molti modi di pelare un gatto (e documentarlo).
      • 3.1.3 Premessa 3: ma, alla fine, perché fare tutta questa fatica se possiamo usare un LLM o un chatbot?
    • 3.2 L’aiuto di R.
      • 3.2.1 Il tab Help di RStudio.
      • 3.2.2 Funzioni per chiedere aiuto.
    • 3.3 Strategie per cercare aiuto (anche senza parere).
    • 3.4 Esercizi.
    • 3.5 Altre risorse.
      • 3.5.1 Risorse in italiano.
      • 3.5.2 Risorse in inglese.
      • 3.5.3 Niente video?
  • 4 Dati, oggetti, funzioni (e tutto il resto)
    • 4.1 Cosa c’è da imparare in questo capitolo.
      • 4.1.1 Premessa 1: esperimenti e osservazioni.
      • 4.1.2 Premessa 2. Misure e dati, osservazioni e variabili, tabelle.
      • 4.1.3 Anatomia di una tabella.
      • 4.1.4 Un piccolo esercizio.
      • 4.1.5 Tidy vs. untidy (tabelle ordinate e disordinate).
      • 4.1.6 Dati mancanti (missing data).
    • 4.2 R è un linguaggio funzionale che supporta la programmazione orientata a oggetti…
    • 4.3 Il nome delle cose.
    • 4.4 Strutture di dati.
    • 4.5 Vettori atomici.
      • 4.5.1 Vettori ad una dimensione.
      • 4.5.2 Vettori atomici a 2 o più dimensioni: matrici e array.
    • 4.6 I data frame e le liste.
      • 4.6.1 I data frame, nel bene e nel male.
      • 4.6.2 Le liste.
    • 4.7 Altre cose strane: tabelle di frequenza e contingenza, serie temporali, date e ore.
    • 4.8 Indirizzare, selezionare.
      • 4.8.1 Indirizzare per posizione.
      • 4.8.2 Usare i nomi.
      • 4.8.3 Usare valori logici.
    • 4.9 attach() e with().
    • 4.10 Funzioni “built-in” e funzioni definite dall’utente.
      • 4.10.1 Semplici funzioni matematiche, trigonometriche, statistiche, logiche, etc.
      • 4.10.2 Operatori.
      • 4.10.3 Funzioni built-in.
      • 4.10.4 Funzioni definite dall’utente.
    • 4.11 Programmare, con stile.
    • 4.12 Un ambiente affollato.
    • 4.13 Oggetti S4
    • 4.14 Altre risorse.
      • 4.14.1 Risorse in italiano.
      • 4.14.2 Risorse in inglese.
  • 5 Dentro e fuori R
    • 5.1 Cosa c’è da imparare in questo capitolo.
    • 5.2 Ogni cosa al suo posto: working directory, progetti, etc.
    • 5.3 Facciamola semplice: il menu Import Dataset.
    • 5.4 Gestire file di testo con readr.
    • 5.5 Tutti i comandi (o quasi) per importare file di testo…
    • 5.6 Il locale.
    • 5.7 Altri formati di dati.
      • 5.7.1 Da e per Excel.
      • 5.7.2 Altri formati: foreign e Hmisc e haven.
      • 5.7.3 Un richiamo: file .Rdata e .rds
      • 5.7.4 E’ andato tutto bene?
    • 5.8 Lavorare con i nomi dei file e le directory.
    • 5.9 Appendice 1. Un piccolo dettaglio sulla sintassi.
    • 5.10 Appendice 2. Se sei arrivat* fin qui…
    • 5.11 Altre risorse.
      • 5.11.1 Risorse in inglese.
  • 6 Introduzione alla grafica scientifica con R
    • 6.1 Cosa c’è da imparare in questo capitolo.
    • 6.2 I grafici, fatti bene.
    • 6.3 I sistemi grafici in R.
    • 6.4 Visualizzare o salvare i grafici: i device.
      • 6.4.1 Salvare i grafici: i file come device grafici.
      • 6.4.2 Salvare i grafici di ggplot2 con ggsave.
      • 6.4.3 Le dimensioni del device e le opzioni grafiche.
    • 6.5 R, a colori.
    • 6.6 La grammatica della grafica con ggplot2.
    • 6.7 Grafici per variabili qualitative.
      • 6.7.1 Diagrammi a barre.
      • 6.7.2 Fare di più con i grafici per variabili qualitative.
    • 6.8 Grafici per variabili quantitative.
      • 6.8.1 Istogrammi e altre rappresentazioni della densità.
      • 6.8.2 Boxplot.
      • 6.8.3 Rappresentazioni di indicatori di tendenza centrale e di variabilità.
      • 6.8.4 Grafici a dispersione.
      • 6.8.5 Personalizzare i grafici con ggplot2.
      • 6.8.6 Estensioni per ggplot2.
      • 6.8.7 Veloce veloce: qplot()
    • 6.9 La grafica di base in R: un salvagente?
    • 6.10 Altre risorse.
      • 6.10.1 Risorse in inglese.
  • 7 Esplorare con i numeri
    • 7.1 Cosa c’è da imparare in questo capitolo.
    • 7.2 Una piccola premessa: gruppi, livelli, sottoinsiemi.
    • 7.3 Statistiche riassuntive per dati continui.
      • 7.3.1 Misure di tendenza centrale e di variabilità.
    • 7.4 Altre funzioni utili.
      • 7.4.1 Lavorare sui vettori.
      • 7.4.2 Funzioni che producono statistiche riassuntive.
      • 7.4.3 Statistiche, ordinate.
      • 7.4.4 Statistiche riassuntive per gruppi.
    • 7.5 Ma è normale?
      • 7.5.1 Normal probability plot.
      • 7.5.2 Test statistici per la normalità.
      • 7.5.3 Come fare di meglio con i risultati dei test.
    • 7.6 Intervalli di confidenza.
    • 7.7 Riassumere i dati per le variabili categoriche.
      • 7.7.1 Tabelle di frequenza e contingenza.
      • 7.7.2 Grafici a mosaico.
    • 7.8 Veloce veloce
    • 7.9 Altre risorse.
      • 7.9.1 Risorse in italiano.
      • 7.9.2 Risorse in inglese.
  • 8 Creare report e notebook con R.
    • 8.1 Cosa c’è da imparare in questo capitolo.
    • 8.2 Il minimo indispensabile.
    • 8.3 Gli elementi di un report in R Markdown.
    • 8.4 Altri formati di documento con R Markdown.
    • 8.5 Quarto.
    • 8.6 Altre risorse.
      • 8.6.1 Risorse in italiano.
      • 8.6.2 Risorse in inglese.
      • 8.6.3 Notebook collaborativi.
  • 9 Lottare con i dati.
    • 9.1 Cosa c’è da imparare in questo capitolo.
    • 9.2 Rendere tidy i dati.
      • 9.2.1 Riordinare con tidyr e dplyr: esempio minimo.
      • 9.2.2 Funzioni avanzate con tidyr.
    • 9.3 Il cavallo di battaglia del data wrangling: dplyr.
      • 9.3.1 Estrarre gruppi di righe o colonne.
      • 9.3.2 Riordinare i dati.
      • 9.3.3 Trasformare con mutate().
      • 9.3.4 Riassumere i dati con summarise().
      • 9.3.5 Database e tabelle relazionali: unire tabelle con _join.
    • 9.4 Strutture di controllo.
      • 9.4.1 Loop (o cicli) e cose simili.
      • 9.4.2 Un’alternativa (veloce e ordinata) ai loop: i “functional”.
      • 9.4.3 Esecuzione condizionale.
    • 9.5 La soluzione dell’esercizio.
    • 9.6 Altre risorse.
      • 9.6.1 Risorse in italiano.
      • 9.6.2 Risorse in inglese.
  • 10 Citazioni, crediti, copyright, ringraziamenti, bibliografia.
    • I pacchetti usati in questo libro.
    • Credits e copyright.
    • Riferimenti bibliografici per i pacchetti.

pigR: R, per pigri

Capitolo 10 Citazioni, crediti, copyright, ringraziamenti, bibliografia.

I pacchetti usati in questo libro.

Ecco una lista dei principali pacchetti usati in questo libro. Sono in ordine alfabetico, e non in ordine di importanza (almeno dal mio punto di vista). Il comando citation() è utile per generare i riferimenti bibliografici che possono essere usati per citare i pacchetti nelle pubblicazioni.

## Warning in xfun::pkg_bib(..., prefix = prefix): package(s) radiant, Rcmdr not found
##  [1] "base"           "beepr"          "broom"          "car"            "cowplot"       
##  [6] "data.table"     "dplyr"          "doBy"           "foreign"        "ggplot2"       
## [11] "ggpubr"         "ggstatsplot"    "gmodels"        "Hmisc"          "knitr"         
## [16] "kableExtra"     "magrittr"       "MASS"           "microbenchmark" "openxlsx"      
## [21] "nortest"        "nycflights13"   "pastecs"        "plyr"           "psych"         
## [26] "purrr"          "radiant"        "Rcmdr"          "RColorBrewer"   "reshape2"      
## [31] "rmarkdown"      "rstatix"        "stringr"        "skimr"          "tictoc"        
## [36] "tidyr"          "tidyverse"      "vcd"

Nota che ho lasciato anche alcuni pacchetti ridondanti o obsoleti. Probabilmente puoi fare quasi tutto quello che è descritto in questo libro, e molto di più con, in ordine di importanza:

  • tidyverse (carica tutti i pacchetti del tidyverse, inclusi dplyr, tidyr, ggplot2, purrr) e molti pacchetti utili, come dipendenze (inclusa la pipe %>%)

  • broom è, letteralmente, il mago dell’output tidy

  • rstatix offre molti test statistici in formato tidy e ggpubr permette di ottenere visualizzazioni efficaci di risultati dei test

  • readxl, se proprio non puoi fare a meno di caricare file MS Excel

  • psych e car includono moltissime funzioni utili per l’analisi statistica

  • `vcd``` utile per dati categorici

Credits e copyright.

La figura usata per la copertina è di Mark Stebnicki da Pexels Di alcune figure del capitolo 3 non sono riuscito a trovare una fonte precisa, neanche usando la ricerca per immagini di Google.
La figura 4.2 è stata modificata a partire dalla figura 1 di Szymańska, E., 2018. Modern data science for analytical chemical data - A comprehensive review. Anal Chim Acta 1028, 1–10..
Ho un debito con i reviewer di questo libro: hanno avuto la pazienza di leggere tutto, cosa che non credo faranno tutt* quell* che, in un modo o nell’altro, lo avranno “fra le mani”.
Gli script usati per generare questo libro sono stati creati da Eugenio Parente (eugenio.parente_at_unibas.it), Università degli Studi della Basilicata, 2021, 2022, 2023, 2026 e sono disponibili su GitHub Gli script sono stati testati (fino a maggio) con R 4.0.5, 4.1, 4.2.2, 4.3.0, 4.3.1, 4.5.2 (sia build per processori Intel che per arm64) e, finalmente, con R 4.6 su diversi personal computer Apple (con MacOS 10.14.6, 10.15.7, 13.6, 26.5.1). Il codice è disponibile in un repository su GitHub (se proprio sei troppo pigr* per scrivere o fare il copia e incolla). Claude AI (Anthropic, modello claude-sonnet-4-6) è stato utilizzato nel 2026 per rivedere la versione finale del testo e del codice e ha mostrato quanto io sia inutile come correttore di bozze.

Le parti di codice sono sotto licenza MIT
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Le parti di testo sono sotto licenza CC BY 4.0.

Riferimenti bibliografici per i pacchetti.

Allaire, J., Xie, Y., Dervieux, C., McPherson, J., Luraschi, J., Ushey, K., Atkins, A., Wickham, H., Cheng, J., Chang, W., & Iannone, R. (2026). Rmarkdown: Dynamic documents for r. https://github.com/rstudio/rmarkdown
Bååth, R. (2024). Beepr: Easily play notification sounds on any platform. https://github.com/rasmusab/beepr
Bache, S. M., & Wickham, H. (2026). Magrittr: A forward-pipe operator for r. https://magrittr.tidyverse.org
Barrett, T., Dowle, M., Srinivasan, A., Gorecki, J., Chirico, M., Hocking, T., Schwendinger, B., & Krylov, I. (2026). Data.table: Extension of ‘data.frame‘. https://r-datatable.com
Fox, J., & Weisberg, S. (2019). An R companion to applied regression (Third). Sage. https://www.john-fox.ca/Companion/
Fox, J., Weisberg, S., & Price, B. (2026). Car: Companion to applied regression. https://github.com/bprice2652/car_repo
Grosjean, P., & Ibanez, F. (2024). Pastecs: Package for analysis of space-time ecological series. https://github.com/SciViews/pastecs
Gross, J., & Ligges, U. (2015). Nortest: Tests for normality. https://doi.org/10.32614/CRAN.package.nortest
Halekoh, U., & Højsgaard, S. (2026). doBy: Groupwise statistics, LSmeans, linear estimates, utilities. https://github.com/hojsgaard/doBy
Harrell Jr, F. E. (2026). Hmisc: Harrell miscellaneous. https://hbiostat.org/R/Hmisc/
Izrailev, S. (2024). Tictoc: Functions for timing r scripts, as well as implementations of "stack" and "StackList" structures. https://github.com/jabiru/tictoc
Kassambara, A. (2026a). Ggpubr: ggplot2 based publication ready plots. https://rpkgs.datanovia.com/ggpubr/
Kassambara, A. (2026b). Rstatix: Pipe-friendly framework for basic statistical tests. https://rpkgs.datanovia.com/rstatix/
Mersmann, O. (2024). Microbenchmark: Accurate timing functions. https://github.com/joshuaulrich/microbenchmark/
Meyer, D., Zeileis, A., & Hornik, K. (2006). The strucplot framework: Visualizing multi-way contingency tables with vcd. Journal of Statistical Software, 17(3), 1–48. https://doi.org/10.18637/jss.v017.i03
Meyer, D., Zeileis, A., Hornik, K., & Friendly, M. (2024). Vcd: Visualizing categorical data. https://doi.org/10.32614/CRAN.package.vcd
Neuwirth, E. (2022). RColorBrewer: ColorBrewer palettes. https://doi.org/10.32614/CRAN.package.RColorBrewer
Patil, I. (2021). Visualizations with statistical details: The ’ggstatsplot’ approach. Journal of Open Source Software, 6(61), 3167. https://doi.org/10.21105/joss.03167
Patil, I. (2026). Ggstatsplot: ggplot2 based plots with statistical details. https://www.indrapatil.com/ggstatsplot/
R Core Team. (2026a). Foreign: Read data stored by minitab, s, SAS, SPSS, stata, systat, weka, dBase, ... https://svn.r-project.org/R-packages/trunk/foreign/
R Core Team. (2026b). R: A language and environment for statistical computing. R Foundation for Statistical Computing. https://doi.org/10.32614/R.manuals
Revelle, W. (2026). Psych: Procedures for psychological, psychometric, and personality research. https://personality-project.org/r/psych/
Ripley, B., & Venables, B. (2025). MASS: Support functions and datasets for venables and ripley’s MASS. http://www.stats.ox.ac.uk/pub/MASS4/
Robinson, D., Hayes, A., Couch, S., & Hvitfeldt, E. (2026). Broom: Convert statistical objects into tidy tibbles. https://broom.tidymodels.org/
Schauberger, P., & Walker, A. (2025). Openxlsx: Read, write and edit xlsx files. https://ycphs.github.io/openxlsx/index.html
Venables, W. N., & Ripley, B. D. (2002). Modern applied statistics with s (Fourth). Springer. https://www.stats.ox.ac.uk/pub/MASS4/
Waring, E., Quinn, M., McNamara, A., Arino de la Rubia, E., Zhu, H., & Ellis, S. (2026). Skimr: Compact and flexible summaries of data. https://docs.ropensci.org/skimr/
Warnes, G. R., Bolker, B., Lumley, T., Johnson, R. C., Jain, N., Schwartz, M., & Rogers, J. (2024). Gmodels: Various r programming tools for model fitting. https://github.com/r-gregmisc/gmodels
Wickham, H. (2007). Reshaping data with the reshape package. Journal of Statistical Software, 21(12), 1–20. https://www.jstatsoft.org/v21/i12/
Wickham, H. (2011). The split-apply-combine strategy for data analysis. Journal of Statistical Software, 40(1), 1–29. https://www.jstatsoft.org/v40/i01/
Wickham, H. (2016). ggplot2: Elegant graphics for data analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org
Wickham, H. (2021). nycflights13: Flights that departed NYC in 2013. https://github.com/hadley/nycflights13
Wickham, H. (2023a). Plyr: Tools for splitting, applying and combining data. http://had.co.nz/plyr
Wickham, H. (2023b). Tidyverse: Easily install and load the tidyverse. https://tidyverse.tidyverse.org
Wickham, H. (2025a). reshape2: Flexibly reshape data: A reboot of the reshape package. https://github.com/hadley/reshape
Wickham, H. (2025b). Stringr: Simple, consistent wrappers for common string operations. https://stringr.tidyverse.org
Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D., François, R., Grolemund, G., Hayes, A., Henry, L., Hester, J., Kuhn, M., Pedersen, T. L., Miller, E., Bache, S. M., Müller, K., Ooms, J., Robinson, D., Seidel, D. P., Spinu, V., … Yutani, H. (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686. https://doi.org/10.21105/joss.01686
Wickham, H., Chang, W., Henry, L., Pedersen, T. L., Takahashi, K., Wilke, C., Woo, K., Yutani, H., Dunnington, D., & van den Brand, T. (2026). ggplot2: Create elegant data visualisations using the grammar of graphics. https://ggplot2.tidyverse.org
Wickham, H., François, R., Henry, L., Müller, K., & Vaughan, D. (2026). Dplyr: A grammar of data manipulation. https://dplyr.tidyverse.org
Wickham, H., & Henry, L. (2026). Purrr: Functional programming tools. https://purrr.tidyverse.org/
Wickham, H., Vaughan, D., & Girlich, M. (2025). Tidyr: Tidy messy data. https://tidyr.tidyverse.org
Wilke, C. O. (2025). Cowplot: Streamlined plot theme and plot annotations for ggplot2. https://wilkelab.org/cowplot/
Xie, Y. (2014). Knitr: A comprehensive tool for reproducible research in R. In V. Stodden, F. Leisch, & R. D. Peng (Eds.), Implementing reproducible computational research. Chapman; Hall/CRC.
Xie, Y. (2015). Dynamic documents with R and knitr (2nd ed.). Chapman; Hall/CRC. https://yihui.org/knitr/
Xie, Y. (2025). Knitr: A general-purpose package for dynamic report generation in r. https://yihui.org/knitr/
Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Chapman; Hall/CRC. https://yihui.org/rmarkdown/
Xie, Y., Dervieux, C., & Riederer, E. (2020). R markdown cookbook. Chapman; Hall/CRC. https://yihui.org/rmarkdown-cookbook
Zeileis, A., Meyer, D., & Hornik, K. (2007). Residual-based shadings for visualizing (conditional) independence. Journal of Computational and Graphical Statistics, 16(3), 507–525. https://doi.org/10.1198/106186007X237856
Zhu, H. (2026). kableExtra: Construct complex table with kable and pipe syntax. https://haozhu233.github.io/kableExtra/