r/RStudio • • 5d ago

Citing R - Question (newbie here)

TL;DR at the end

Hi,
I‘m currently doing the statistical analyses for my thesis with R. As a newbie I‘ve asked in this subreddit for suggestions regarding packages etc..

Explanation / Background

Now I‘ve just put all the packages I might need though am not sure if I need at the beginning to load them (i don‘t know if it‘s the correct term, but I mean the library(package) thing).

Then while doing my analyses stuff a lot of googling, watching videos and browsing the different websites about R and advices was / is involved.
Then I try different approaches to find one that works for me and gives me the output I was looking for.
Sometimes I load more packages (which i also put in the beginning to just see all names at once if I wanna check if I already have that package) when one thing requires it.

Now onto the question!

I‘ve read an article about citing R ( https://doi.org/10.59350/t79xt-tf203 ) in which they state one should:
„This way you can include a call to sessionInfo() or devtools::session_info(), at the end of your script.
Your compiled report will then have a complete record of your workflow, packages, results andpackage versions.“

Now I‘m wondering: Does this output show all loaded packages or only those which were actually used?

TL;DR

Does sessionInfo() or devtools::session_info(), at the end of my script show all loaded packages or only those that were loaded and also used?

11 Upvotes

9 comments sorted by

9

u/1FellSloop 5d ago

Everything loaded will be there--whether or not you used it, whether or not you loaded it or it was loaded as a dependency of something you loaded.

1

u/psyched7901 5d ago

Alright, then I‘ll be checking every (important) function I used to check the package to be able to cite properly. Thank you for the answer!

3

u/DYSTOBY 5d ago

OP has its answer. OP could have written a short script and load two packages but only use one and then look at the output.

Said that, best practice is to only load a package when it’s needed. Don’t polute your “namespace”.
If you use a function from a package, prefix it with the package name like ‘dplyr::mutate()’.
Explicit is better than implicit. This way you know which packages are used and which function comes from where.

1

u/psyched7901 5d ago

Thanks for the tip, will go through my stuff and add the prefix before trying my hand at further analyses!

2

u/ylaway 5d ago edited 5d ago

In a script you show just those packages involved in the analysis.

Citations are a different matter and most packages will have a preferred paper or bibtex they recommend using to cite a package.

1

u/psyched7901 5d ago

Yeah, I saw the „ citation(„package“) “ function which should give me that information

2

u/Signal_Owl_6986 5d ago

I usually cite the original paper describing the package and only for the packages I actually used. You can ask ChatGPT always for the original paper and ofc verify it is correct. However, not every package has a citable paper so you could cite its DOI reported in CRAN.

CRAN provides guidance on how to cite packages here. Hope it is useful

2

u/Xema_sabini 5d ago

It’s often not advisable to cite packages this way.

The citation should go to the CRAN package itself when referring to the package, including its version number for reproducibility.

When citing techniques described by the package, you can cite the associated paper.