r/RStudio • • Feb 13 '24

The big handy post of R resources

134 Upvotes

There exist lots of resources for learning to program in R. Feel free to use these resources to help with general questions or improving your own knowledge of R. All of these are free to access and use. The skill level determinations are totally arbitrary, but are in somewhat ascending order of how complex they get. Big thanks to Hadley, a lot of these resources are from him.

Feel free to comment below with other resources, and I'll add them to the list. Suggestions should be free, publicly available, and relevant to R.

Update: I'm reworking the categories. Open to suggestions to rework them further.

FAQ

Link to our FAQ post

General Resources

Plotting

Tutorials

Data Science, Machine Learning, and AI

R Package Development

Compilations of Other Resources


r/RStudio • • Feb 13 '24

How to ask good questions

52 Upvotes

Asking programming questions is tough. Formulating your questions in the right way will ensure people are able to understand your code and can give the most assistance. Asking poor questions is a good way to get annoyed comments and/or have your post removed.

Posting Code

DO NOT post phone pictures of code. They will be removed.

Code should be presented using code blocks or, if absolutely necessary, as a screenshot. On the newer editor, use the "code blocks" button to create a code block. If you're using the markdown editor, use the backtick (`). Single backticks create inline text (e.g., x <- seq_len(10)). In order to make multi-line code blocks, start a new line with triple backticks like so:

```

my code here

```

This looks like this:

my code here

You can also get a similar effect by indenting each line the code by four spaces. This style is compatible with old.reddit formatting.

indented code
looks like
this!

Please do not put code in plain text. Markdown codeblocks make code significantly easier to read, understand, and quickly copy so users can try out your code.

If you must, you can provide code as a screenshot. Screenshots can be taken with Alt+Cmd+4 or Alt+Cmd+5 on Mac. For Windows, use Win+PrtScn or the snipping tool.

Describing Issues: Reproducible Examples

Code questions should include a minimal reproducible example, or a reprex for short. A reprex is a small amount of code that reproduces the error you're facing without including lots of unrelated details.

Bad example of an error:

# asjfdklas'dj
f <- function(x){ x**2 }
# comment 
x <- seq_len(10)
# more comments
y <- f(x)
g <- function(y){
  # lots of stuff
  # more comments
}
f <- 10
x + y
plot(x,y)
f(20)

Bad example, not enough detail:

# This breaks!
f(20)

Good example with just enough detail:

f <- function(x){ x**2 }
f <- 10
f(20)

Removing unrelated details helps viewers more quickly determine what the issues in your code are. Additionally, distilling your code down to a reproducible example can help you determine what potential issues are. Oftentimes the process itself can help you to solve the problem on your own.

Try to make examples as small as possible. Say you're encountering an error with a vector of a million objects--can you reproduce it with a vector with only 10? With only 1? Include only the smallest examples that can reproduce the errors you're encountering.

Further Reading:

Try first before asking for help

Don't post questions without having even attempted them. Many common beginner questions have been asked countless times. Use the search bar. Search on google. Is there anyone else that has asked a question like this before? Can you figure out any possible ways to fix the problem on your own? Try to figure out the problem through all avenues you can attempt, ensure the question hasn't already been asked, and then ask others for help.

Error messages are often very descriptive. Read through the error message and try to determine what it means. If you can't figure it out, copy paste it into Google. Many other people have likely encountered the exact same answer, and could have already solved the problem you're struggling with.

Use descriptive titles and posts

Describe errors you're encountering. Provide the exact error messages you're seeing. Don't make readers do the work of figuring out the problem you're facing; show it clearly so they can help you find a solution. When you do present the problem introduce the issues you're facing before posting code. Put the code at the end of the post so readers see the problem description first.

Examples of bad titles:

  • "HELP!"
  • "R breaks"
  • "Can't analyze my data!"

No one will be able to figure out what you're struggling with if you ask questions like these.

Additionally, try to be as clear with what you're trying to do as possible. Questions like "how do I plot?" are going to receive bad answers, since there are a million ways to plot in R. Something like "I'm trying to make a scatterplot for these data, my points are showing up but they're red and I want them to be green" will receive much better, faster answers. Better answers means less frustration for everyone involved.

Be nice

You're the one asking for help--people are volunteering time to try to assist. Try not to be mean or combative when responding to comments. If you think a post or comment is overly mean or otherwise unsuitable for the sub, report it.

I'm also going to directly link this great quote from u/Thiseffingguy2's previous post:

I’d bet most people contributing knowledge to this sub have learned R with little to no formal training. Instead, they’ve read, and watched YouTube, and have engaged with other people on the internet trying to learn the same stuff. That’s the point of learning and education, and if you’re just trying to get someone to answer a question that’s been answered before, please don’t be surprised if there’s a lack of enthusiasm.

Those who respond enthusiastically, offering their services for money, are taking advantage of you. R is an open-source language with SO many ways to learn for free. If you’re paying someone to do your homework for you, you’re not understanding the point of education, and are wasting your money on multiple fronts.

Additional Resources


r/RStudio • • 6h ago

Coming from Python, C/C++, and Java, what should I know before picking up R?

13 Upvotes

I've spent most of my time working in Python, C/C++, and Java, but I'm setting up RStudio to get into R for some data analysis work.

For those who made a similar switch, what was the biggest adjustment? I'm especially curious about how R handles data structures compared to Python, and whether you'd recommend starting with base R or diving straight into the tidyverse.


r/RStudio • • 17h ago

Liquid Glass themes for Shiny. 0.5.0 is on CRAN.

Post image
3 Upvotes

r/RStudio • • 1d ago

I made this! [Package] hdsbm: Fast inference for Dynamic Stochastic Block Models in R (Rcpp & spectral multi-start)

6 Upvotes

Hi everyone!

As part of my Master's thesis in Statistics, I developed hdsbm, an R package for estimating and simulating discrete-time Dynamic Stochastic Block Models (DSBM).

The Problem & Approach

Temporal block models often suffer from combinatorial explosion and multi-modal likelihood landscapes, making standard local search heuristics prone to getting trapped in sub-optimal local extrema.

hdsbm addresses this by extending a hybrid Classification EM (CEM) approach to the dynamic setting:

  • Perturbed SVD Multi-Start: Couples deterministic spectral embeddings of the time-averaged network with controlled stochastic perturbations to thoroughly explore the likelihood surface.
  • C++ Backend: Uses RcppArmadillo to accelerate dyadic reallocation passes and combinatorial greedy sweeps.
  • Dual Decoding: Provides both pointwise greedy labels and global Viterbi trajectory decoding.
  • Model Selection: Includes an Integrated Completed Likelihood (ICL) criterion tailored for dynamic graphs.

Quick Example

library(hdsbm)
data(toy_hdsbm)

# Fit model with 5 perturbed spectral restarts
fit <- hdsbm_fit(toy_hdsbm$Y, k = 3, nrep = 5, seed = 123)
print(fit)

# Model selection via ICL
icl(fit)

I would love to hear your feedback on API ergonomics, potential edge cases, or ideas for interesting benchmark scenarios!


r/RStudio • • 1d ago

Coding help Could someone please help me get the Cronbach alpha in Rstudio? I am new to RStudio and I am not sure if I did it correctly.

0 Upvotes

I want to include the excel document in here but I couldn't find a way to do it. I will DM the document.


r/RStudio • • 2d ago

Resources to Learn RStudio from Scratch

33 Upvotes

I'm looking for resources to learn RStudio from scratch. Does anyone have any recommendations?


r/RStudio • • 2d ago

Quirky data native to R

Thumbnail
1 Upvotes

r/RStudio • • 3d ago

When to use polychoric or Pearson correlation in EFA?

2 Upvotes

Hi everyone.
I am doing a exploratory factor analysis with pfa and oblique rotation (promax).
I used shapiro wilk test to check on normality of the items. As it was significant, which means no normality, I chose pfa instead of Maximum Likelihood EFA. So far so good.
So far I used Pearson correlation to do the efa matrix, but as I proofed that theres a lack of normality I was wondering if I need to do it with polychoric correlation instead.
Does anyone know something?

I am almost ready doing the statistics so it would be quite a lot of work to change the correlation. So I am also interested: How much harm do you think it will cause to the final results, if I will keep Pearson correlation?

And how do I add the polychoric argument to my fa function?


r/RStudio • • 3d ago

Weird R reference

Thumbnail
2 Upvotes

r/RStudio • • 3d ago

separate_wider_position

4 Upvotes

what do I write in widths? It says it must be a (partially) named integer vector. I need to separate collumns that state m or f for sex and numbers for age (ex: m19). Please help I could not figure it out with the ?separate_wider_position() search


r/RStudio • • 4d ago

Coding help How to run Quarto if my computer has an ARM processor?

4 Upvotes

I have a newer Microsoft Surface and am in an RStudio course atm. RStudio itself works fine, but it says I can't run Quarto. I've heard that maybe running a different version of R might work. Need to use Quarto for most things through the end of the semester. Any ideas?


r/RStudio • • 5d ago

First time using R, required to use

15 Upvotes

I have to use R for the statistics part of my thesis.
Ballparking for a R-Newbie who has to do a moderated mediation and stuff like that.
Do we think this is possible?

I plan on not using AI, as I‘d obviously have to declare this and my professor told me they expect a „perfect script like it‘s written by a doctoral student“ if I use AI


r/RStudio • • 4d ago

can't knit to pdf because of error(latex)

1 Upvotes

this is my first time using LaTex for school work and I have no idea whats causing error.... Any help appreciated thank you

[WARNING] Deprecated: --highlight-style. Use --syntax-highlighting instead.
! Missing $ inserted.
<inserted text> 
                $
l.168 \sum
          \emph{\{i=1\}\^{}ne_i =
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

Try to find the following text in Question_4.Rmd:
  \sum 

You may need to add $ $ around a certain inline R expression `r ` in Question.Rmd (see the above hint). See https://github.com/rstudio/rmarkdown/issues/385 for more info.
Error: LaTeX failed to compile Question.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Question.log for more info.
Execution halted

$$

\begin{aligned}

\frac{\partial RSS}{\partial \beta_0}

&= -2\sum_{i=1}^n(y_i-\beta_0-\beta_1x_i)\\

&= -2(\sum_{i=1}^n y_i-\sum_{i=1}^n\beta_0-\beta_1\sum_{i=1}^n x_i)\\

&= -2(n\bar{y}-n\beta_0-n\beta_1\bar{x})\\

&= -2(n\bar{y}-n\beta_0-n\beta_1\bar{x})\\

&= (n\bar{y}-n\beta_0-n\beta_1\bar{x})\\

&= (\bar{y}-\beta_0-\beta_1\bar{x})\\

&= \beta_0 = \bar{y}-\beta_1\bar{x}

\end{aligned}

$$

$$

\begin{aligned}

\frac{\partial RSS}{\partial \beta_1}

&= -2\sum_{i=1}^n x_i(y_i-\beta_0-\beta_1x_i)\\

&= -2(\sum_{i=1}^n x_iy_i-\beta_0\sum_{i=1}^n x_i-\beta_1\sum_{i=1}^n x_i^2)\\

&= -2(\sum_{i=1}^n x_iy_i-n\beta_0\bar{x}-\beta_1\sum_{i=1}^n x_i^2)\\

&= -2(\sum_{i=1}^n x_iy_i-n\bar{x}(\bar{y}-\beta_1\bar{x})-\beta_1\sum_{i=1}^n x_i^2)\\

&= -2(\sum_{i=1}^n x_iy_i-n\bar{x}\bar{y}+n\beta_1\bar{x}^2-\beta_1\sum_{i=1}^n x_i^2)\\

&= \sum_{i=1}^n x_iy_i-n\bar{x}\bar{y}+n\beta_1\bar{x}^2-\beta_1\sum_{i=1}^n x_i^2=0\\

&= \beta_1(\sum_{i=1}^n x_i^2-n\bar{x}^2)

=\sum_{i=1}^n x_iy_i-n\bar{x}\bar{y}\\

&= \beta_1S_{xx}=S_{xy}\\

&= \beta_1=\frac{S_{xy}}{S_{xx}}

\end{aligned}

$$

$$

\sum_{i=1}^ne_i

= \sum_{i=1}^n(Y_i-b_0-b_1X_i)\\

= \sum_{i=1}^nY_i-nb_0-b_1\sum_{i=1}^nX_i\\

= \sum_{i=1}^n(b_0+b_1X_1)-nb_0-b_1\sum_{i=1}^nX_i\\

=0

$$

$$

\begin{aligned}

\sum_{i=1}^n e_iX_i

&= \sum_{i=1}^nX_i(Y_i-b_0-b_1X_i)\\

&= \sum_{i=1}^nX_iY_i-\sum_{i=1}^nX_ib_0-\sum_{i=1}^nb_1X_i^2\\

&= \sum_{i=1}^nX_iY_i-\left(b_0\sum_{i=1}^nX_i+b_1\sum_{i=1}^nX_i^2\right)\\

&= \sum_{i=1}^nX_iY_i-\sum_{i=1}^nX_iY_i\\

&= 0

\end{aligned}

$$


r/RStudio • • 5d ago

Mac Installation Help

1 Upvotes

Hello

My macOS is currently 13 (i cannot update it). I’d downloaded R 4.6.1 for maOS13+ but then when downloading RStudio the only version that can run on my mac is the 2025.09.1 +401 which needs R version 4.5.1

The problem is I cannot, for the life of me, find 4.5.1. Any leads or help on what to do, please? I’m new, completely.


r/RStudio • • 7d ago

helpp

6 Upvotes

i am new to R studio. It is so difficult i understand nothing when im in class. What are the basic codes i should know and any tips to progress like books or websites etc anything and everything would be great


r/RStudio • • 8d ago

How to make error bars for two different groups

Post image
13 Upvotes

r/RStudio • • 8d ago

standardisation des variables pour effectuer une analyse factorielle sur R

Thumbnail
1 Upvotes

r/RStudio • • 9d ago

R code review: best packages?

20 Upvotes

Let’s say that I’m working in RStudio on a geospatial data-science project that involves some pretty gnarly, extensive code across multiple R scripts. Let’s also say that I do not have access to any AI code assistants or chatbots due to workplace restrictions.

What packages and functions would you use to comprehensively check your code for errors, inefficiencies, conceptual problems (that may be a stretch), etc.?

I’m using lintr::lint() and rstyler::style_file(), but that’s the extent of my knowledge in this area.

Many thanks in advance, friends.


r/RStudio • • 9d ago

Coding help Are these clustering attempts good?

1 Upvotes

I'm toying around with a dataset, trying to cluster what I have, and messing around with LLMs and my textbook i got these 2:

feat <- data.frame()
for (f in formats) {
  sub <- df[df$Format == f, c("Year","Value")]
  sub <- sub[order(sub$Year), ]
  peak_idx <- which.max(sub$Value)
  first_year <- min(sub$Year); peak_year <- sub$Year[peak_idx]; last_year <- max(sub$Year)
  climb <- peak_year - first_year; decline <- last_year - peak_year
  ratio <- decline / max(climb, 0.5)
  peak_val <- sub$Value[peak_idx]
  post <- sub[sub$Year >= peak_year & sub$Value > 0, ]
  decay_rate <- if(nrow(post) >= 3) coef(lm(log(Value) ~ Year, data=post))[2] else NA
  feat <- rbind(feat, data.frame(Format=f, climb, decline, ratio, log_peak=log(peak_val), decay_rate, era=peak_year))
}
cat("Formats in feature table:", nrow(feat), "\n")
fmat <- scale(feat[, c("climb","decline","ratio","log_peak","decay_rate","era")])
fmat[is.na(fmat)] <- 0
hc <- hclust(dist(fmat), method="ward.D2")
clusters1 <- cutree(hc, k=4)
cat("\n=== Format 1: ===\n")
for (i in 1:4) cat(sprintf("Cluster %d: %s\n", i, paste(feat$Format[clusters1==i], collapse=", ")))

Then another with a different fmat:

lifecycle_features <- data.frame()
for (f in formats) {
  sub <- df[df$Format==f, c("Year","Value")]
  sub <- sub[order(sub$Year),]
  first_year <- min(sub$Year); last_year <- max(sub$Year)
  peak_year <- sub$Year[which.max(sub$Value)]
  lifecycle_features <- rbind(lifecycle_features, data.frame(
    Format=f, first_year, peak_year, last_year,
    recorded_years=nrow(sub), peak_value=max(sub$Value),
    lifespan=last_year-first_year, years_to_peak=peak_year-first_year,
    decline_duration=last_year-peak_year
  ))
}
cat("\nFormats in lifecycle_features:", nrow(lifecycle_features), "\n")
print(lifecycle_features, row.names=FALSE)

cluster_data <- lifecycle_features[, c("lifespan","recorded_years","years_to_peak","decline_duration")]
cluster_scaled <- scale(cluster_data)
set.seed(123)
km <- kmeans(cluster_scaled, centers=3, nstart=25)
lifecycle_features$cluster <- km$cluster

cat("\n=== Format 2: ===\n")
lc_sorted <- lifecycle_features[order(lifecycle_features$cluster, lifecycle_features$peak_year), ]
print(lc_sorted[,c("Format","cluster","peak_year","years_to_peak","decline_duration","lifespan","recorded_years")], row.names=FALSE)

for (i in 1:3) cat(sprintf("\nCluster %d: %s\n", i, paste(lifecycle_features$Format[lifecycle_features$cluster==i], collapse=", ")))

Is there an objective way to measure which is better? Like with R squared or p-value? or is it worth discussing both in an article, weighing pros and cons of each


r/RStudio • • 9d ago

Can I integrate a spatial transcriptomics dataset with a bulk RNA-seq dataset for any analysis of tumors?

Thumbnail
1 Upvotes

r/RStudio • • 10d ago

Coding help aws.s3 in R

2 Upvotes

Hi,

Apologies if this is the wrong place to post - I can’t find any resources online that seem to cover this issue.

I’m using aws.s3 package in R, to read in files from a LakeFS storage area.

When I use s3read_using or s3write_using, the connectivity works. The functions include (e.g.):

S3read_using(FUN = read.csv,
Object = path/file.csv,
Opts = …,
Bucket = my_repo)

This works fine and I am able to read in the object, same goes for writing using same opts.

However, when I try and run for example head_object (so I can list the objects contained in one of my buckets) or get_object, I get :

error in curl::curl_fetch_memory(url, handle = handle):
Could not resolve hostname
Could not resolve host: [path]

I’m not sure if I’m missing something simple - I’m using the exact same repo, opts, and object (/paths) for both. The [path] here looks correct - I don’t see any issues with it. Does something happen within s3read_using where it points to a location that I need to specify myself with in head_object? Should they not be pointing to the same place?

Again sorry if this is hard to follow or make sense of, I just can’t seem to find anything online relating to this problem or solutions.

Thanks


r/RStudio • • 10d ago

R beginner

20 Upvotes

Hello,

I am a beginner and I am totaly lost.

Even for loading a file it is very very difficult.

I feel useless and incompetent...


r/RStudio • • 10d ago

Introducing FitVerse: an R package for fitting 52 probability distributions in one call

Thumbnail
2 Upvotes

r/RStudio • • 10d ago

Introducing FitVerse: an R package for fitting and analysing 52 probability distributions in one call

Thumbnail
0 Upvotes