r/RStudio • • Feb 13 '24 Bravo Silver is Forever

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 Silver is Forever

How to ask good questions

51 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 • • 2d ago

Coding help md5sum hashes of file not matching

5 Upvotes

This should be straightforward, but am struggling to get this to work. I've tried the digest and openssl libraries and neither matches what I get on the commandline.

Obviously the first thing to get right was to ensure I wasn't just hashing the filename (d'oh!). With the digest function I used this:

digest(file(system.file("myfile")), "md5")

Which concerningly returns a different result each time it runs.

With the openssl md5() function I ran:

md5(file(system.file("myfile")))

Which at least is consistent, but only returns the serialised output and doesn't match the output I get on the commandline with md5sum (on macOS).

Help. How do I get an md5sum in R that matches what I get on the commandline? NB: I don't want to do a system call as this needs to be cross platform.


r/RStudio • • 3d ago

Coding help Desperate for help understanding Rstudio and and how to do an ANOVA

28 Upvotes

I am a physiology grad student who has never taken a statistics course or anything. I am genuinely desperate for any help at this point and if anyone at all is willing to zoom with me to help, even for just five minutes, I would greatly appreciate it


r/RStudio • • 3d ago

Coding help Making text in my xtable smaller (r sweave document)

3 Upvotes

Hi.

I wanted to have smaller text in my table. I used \tiny but it did not seem to work. What am I doing wrong?, and how would you guys reccomend getting smaller text in a table?

MRE

\documentclass{article}
\begin{document}
<<package, include=FALSE>>=
library(xtable)
library(survival)
@

<<data,include=FALSE>>=
lung <- lung
@
\tiny
<<table, echo=FALSE,results='asis'>>=
xtable(lung)
@
\end{document}

EDIT: I think i figured it out with

table <- xtable(lung)

print(table, size="\\tiny")

r/RStudio • • 3d ago

Remedy for statistically significant interaction term in Schoenfeld residual (programming in R) [thesis]

0 Upvotes

Dear all!

I am conducting a Cox proportional hazards analysis and tested the proportional hazards assumption using Schoenfeld residuals. Two interaction terms between predictors showed statistically significant results, suggesting that these effects may vary over time. I am therefore unsure which approach would be most appropriate in R to address this.

Would tt() be suitable in this case? Would it work for interaction terms?

Initially I was thinking of tmerge(), but that doesn't work because this would only work if it is the treatment, right? (although the interaction is between treatment group and an intake variable).

I initially also thought of using strata(), but I guess that's only for categorical variables?

I would be very grateful for any advice on how to handle this appropriately in R, and what remedy there is. Recommendations for relevant literature would also be very welcome.


r/RStudio • • 4d ago

RgentAI (Cheaper Posit Assistant Alternative in RStudio)

14 Upvotes

I founded RgentAI over a year ago. It was the first AI inside RStudio before the Posit Assistant release. After the release of Posit Assistant and my PhD keeping me extremely busy, I did very little marketing and development for RgentAI. Surprisingly, it kept getting new users anyway, so I took a closer look at the market...

Posit costs twice as much ($20 vs $10) and gives you less usage. No wonder we were getting new customers! That told me Rgent was worth investing in, so I spent the last few weeks adding new features and reworking it.

The short video below shows the new features, look, and experience! If you're looking for a cheaper alternative to Posit Assistant with more usage inside RStudio, this could be worth checking out!


r/RStudio • • 4d ago Bravo

I made this! FigureIDE : New IDE for R with vector graphic editor

20 Upvotes

I've been developing FigureIDE, open-source desktop application for creating and editing scientific figures using R.

FigureIDE is built on the open-source VectorCraft project, with AI tools(Thanks to Codex and Gemini).

The first Windows beta is now available!

GitHub: https://github.com/newkor3185-blip/FigureIDE

Demo Video: https://youtu.be/ay1fmnCTgsg

I'm still improving the software and would really appreciate feedback from you.
Contributions are also welcome!


r/RStudio • • 4d ago

Soundboarding [Discussion]

Thumbnail reddit.com
4 Upvotes

r/RStudio • • 4d ago

Remedy for statistically significant interaction term in Schoenfeld residual (programming in R) [thesis]

3 Upvotes

Dear all!

I am conducting a Cox proportional hazards analysis and tested the proportional hazards assumption using Schoenfeld residuals. Two interaction terms between predictors showed statistically significant results, suggesting that these effects may vary over time. I am therefore unsure which approach would be most appropriate in R to address this.

Would tt() be suitable in this case? Would it work for interaction terms?

Initially I was thinking of tmerge(), but that doesn't work because this would only work if it is the treatment, right? (although the interaction is between treatment group and an intake variable).

I initially also thought of using strata(), but I guess that's only for categorical variables?

I would be very grateful for any advice on how to handle this appropriately in R, and what remedy there is. Recommendations for relevant literature would also be very welcome.


r/RStudio • • 4d ago

Can Existing Local Shiny Apps Be Deployed Through Dataiku Without Using Its Low-Code Features?

8 Upvotes

Our company uses Dataiku, and I'm exploring whether it could serve as a deployment platform for several R Shiny applications I've already developed and currently run locally.

I'm not interested in Dataiku's no-code or low-code development capabilities. My goal is simply to deploy my existing Shiny applications so that other employees can access them through a web browser.

Unfortunately, we don't have access to Shiny Server, Posit Connect, or shinyapps.io.

I've come across several Dataiku articles highlighting its deep integration with R and support for web applications built using frameworks such as Shiny, Dash, and Bokeh.

https://doc.dataiku.com/dss/latest/R/index.html
https://doc.dataiku.com/dss/latest/webapps/shiny.html

I have a few questions:

  1. Deployment feasibility: Can an existing, fully functional R Shiny application be deployed directly through Dataiku without substantially modifying its code?

  2. R package dependencies: My applications depend on numerous R packages. Can these be installed within Dataiku, or would IT administrator privileges be required?

  3. Deployment process: How straightforward is the deployment process? Can I upload my existing app.R file and supporting files, configure dependencies, and publish the application?

  4. Licensing and permissions: Does hosting Shiny applications require additional Dataiku licenses, plugins, or administrative configuration?

When running these applications locally, I've generally been able to install R packages without administrator privileges. I'm particularly interested in whether Dataiku offers similar flexibility.

Has anyone successfully deployed existing R Shiny applications through Dataiku? How does the experience compare with using a dedicated Shiny hosting platform?


r/RStudio • • 5d ago

Remedy for statistically significant interaction term in Schoenfeld residual (programming in R) [thesis]

Thumbnail reddit.com
2 Upvotes

r/RStudio • • 7d ago

Coding help STATISTICAL LEARNING aiuto

11 Upvotes

Ciao a tutti/e, faccio la magistrale in International Management a Pavia e sto avendo problemi con il corso di Statistical Learning il quale consiste nell’utilizzo di Rstudio per creare modelli adatti ad interpretare i dati.
Qualcuno saprebbe dare una mano? (Appunti, approccio allo studio, qualsiasi cosa🙏🏼)


r/RStudio • • 11d ago

Coding help Factor vs component: I need help!

5 Upvotes

Hi all,

I am analyzing some data from a questionnaire. I have never done this before and I feel confused.

pa <- psych::fa.parallel(
EnglishDom_vars,
fm = "ml",
use = "pairwise",
n.iter = 1000)

The output (R studio) gives

Parallel analysis suggests that the number of factors = 3 and the number of components = 1

Can someone explain the difference between a factor and a component?

Thanks!


r/RStudio • • 11d ago

Studium rin Modul mit R

15 Upvotes

Hi, ich wollte mir einen laptop fürs Studium kaufen. Wir haben im 2. Semester ein Modul Statistik, wo wir mit R arbeiten und die Prüfung auf windows haben. Meine frage ist jetzt: wenn ich die ganze zeit auf dem Macbook üben würde, hätte ich dann Schwierigkeiten die Prüfung in R auf dem windows pc def Hochschule abzulegen?


r/RStudio • • 11d ago

How do I find code for doing a Brownian Bridge Movement Model? (BBMM)

13 Upvotes

I'm doing my masters in wildlife ecology and have to do a brownian bridge movement model for my analysis.

I'm not entirely new to using R, but this is my first time doing a bigger analysis on my own. My supervisor is mostly hands off when it comes to coding in R and so I feel a bit lost because I'm not sure where to start.

Is there a best method for this step? Like reading papers that have used this and then go off of their code? Or using websites like this: https://rdrr.io/cran/BBMM/man/BBMM-package.html ?

I'm just not sure how to read these instructions :(


r/RStudio • • 12d ago

Cannot launch Rstudio/Bibliometrix - Independent/Early researcher

Thumbnail reddit.com
3 Upvotes

r/RStudio • • 12d ago

Is there a package analogous to the Github Copilot extension for VS Code

11 Upvotes

I've been using GH Copilot in VS Code for some months now via corporate subscription and I wanted to see about using it in RStudio and feel a bit confused.

I've run across chattr and ellmer, but they don't seem the same as the VS Code extension where I can chat prompts and have the model write full functions, consult background data, troubleshoot, write tests, etc.

I see the comment/question bit, but nothing as full featured as VS Code.

In addition, the VS Code extension provides maybe 15 models to choose from, including an auto mode, where it provides a 10% token discount and will pick a model based on complexity. chattr looks to require setting a model... I feel a bit like a dummy, but I assumed the models available in VS Code were coming via my corporate GH Copilot license, or just generally whatever GH Copilot is partnered up with. This includes seeing notices like "Model x.y is going away starting on [date]."

Point being, there is something very "automatic/organic" with the VS Code <-> GH Copilot integration and I am not seeing it on the RStudio side.

Am I just fully misunderstanding the state of the RStudio integration or how folks use it? Is everyone doing this?

# write a function here that [description]

I'd often do a /plan session in VS Code to discuss a larger project, and then can cut it loose to scaffold things vs. having to do this as one-at-a-time prompts via comments. Thanks for any guidance.


r/RStudio • • 12d ago

Coding help Question about merging columns with numeric value or NA (keeping only numeric value)

8 Upvotes

Hello!

Apologies for this possibly very silly question, but I have been trying to figure this out without the help of AI (trying to better understand what I am 'asking' code to do and avoid AI generally) and am losing my marbles a little on one likely very simple element!

I have a dataset where participants were assigned to one of 4 groups (V1, V2, V3, V4). In my Qualtrics survey, I accidentally made it so that the data output has separate columns for each question for each group, although all participants answered the same measures (were just assigned different vignettes).

I have made a variable/column for the condition assignment and have made the below columns summing the measure score for all 4 groups:

dat_clean <- AttributionQuestionnaire <- mutate(

dat_clean,

AQsum1 = V1_Q1_1 + V1_Q1_2 + V1_Q1_3 + V1_Q1_4 + V1_Q1_5 + V1_Q1_6 + V1_Q1_7,

AQsum2 = V2_Q1_1 + V2_Q1_2 + V2_Q1_3 + V2_Q1_4 + V2_Q1_5 + V2_Q1_6 + V2_Q1_7,

AQsum3 = V3_Q1_1 + V3_Q1_2 + V3_Q1_3 + V3_Q1_4 + V3_Q1_5 + V3_Q1_6 + V3_Q1_7,

AQsum4 = V4_Q1_1 + V4_Q1_2 + V4_Q1_3 + V4_Q1_4 + V4_Q1_5 + V4_Q1_6 + V4_Q1_7

)

However I am stuck on how to merge these 4 columns into one. If a person was assigned to V1, their score for AQsum2-4 columns would be NA and their score for AQsum1 column would be the numeric value. Ideally I want a column that is only the AQ scores for all participants.

Thanks very much in advance for your help!


r/RStudio • • 13d ago

shinyglass 0.6.0 on CRAN - Liquid Glass themes for Shiny

Thumbnail reddit.com
3 Upvotes

r/RStudio • • 14d ago

Has anyone tried the dsge package in R?

0 Upvotes

Hi everyone,

The dsge package came up during an R course I’m involved in with a group of macroeconomists. Has anyone here used it for teaching or research?

It supports DSGE model solution and estimation, impulse responses, forecasting and shock decomposition. One feature that caught our attention is importing supported Dynare .mod files and working with the models directly in R, without installing MATLAB, Octave or Dynare.

I’d be interested in hearing how it has worked with your models, especially estimation and comparisons with Dynare. Any examples worth trying or limitations you’ve encountered?


r/RStudio • • 16d ago

Coding help Deleting specific row (not by row number)

15 Upvotes

hi,
i (r newbie) want to delete 1 specific row in my data frame and i don‘t wanna delete it by saying delete row nr. 400.

It‘s the only row that answered 10 specific items with the score 5.

Would the following code work correctly (i‘m worried about destroying my df if i just try to be honest)
(using c1 and following as column names right now)

df <- df %>% dplyr::filter(c1 = 5 && c2 = 5 && […] c10 = 5)

?

Edit: Solution that worked for me

df <- df %>% dplyr::filter(!(df$01 == 5 & df$02 == 5 & df$03 == 5 & df$04 == 5 & df$05 == 5 & df$06 == 5 & df$07 == 5 & df$08 == 5 & df$09 == 5 ))

there‘s probably a more elegant solution but it removed the specific row i needed removed


r/RStudio • • 15d ago

Can´t tell me this isn´t on purpose

0 Upvotes

So today we used the "tidyverse" package at university. I´ve used it at length before but never paid much attention to what was actually installing. Looking at the console there is now definitive proof that there HAS to be some sort of connection to the furry community:

you can find "forcats", "purrr", "stringr" and (and I wish I was making this up) "lubridate" listed in the console when loading the package. Tell me I´m wrong!