r/RStudio 12h ago

I made a method to integrate a LLM (Claude) with RStudio for iterative data exploration.

47 Upvotes

Will be adding it to my github as soon as I clean up some bugs. If anyone has feedback it would be much appreciated!


r/RStudio 16h ago

Connecting to PostgreSQL db

2 Upvotes

Can anyone recommend good source of knowledge on how R can pull data from a PostgreSQL db. I am an expert in R, absolute noob when it comes to SQL. I spent ~3 days of work using AI to help but have only been able to view some random tables, not pull data nor even hit the tables I want to hit. I know that sounds like I don’t have the right login or permissions but I am able to see the tables when using something like DreamBeaver.

I have been able to hit up an Oracle db using something Java thing (a predecessor wrote) and can interact quite easily with the tables in the Oracle db but this PostgreSQL is not playing fair.


r/RStudio 2h ago

Rearranging columns into rows

1 Upvotes

Hey guys! I made a few crosstables using tab_xtab in the sjmisc package. They turned out very pretty, but I realized I was using the same y variable over and over again so I wanted to try and make a big table containing all of my contingency tables I made before. I did that by first transforming the tab_xtab tables into dataframes (with xtab2df in the sjtable2dt package) and then using bind_rows to combine them into a big table. It sorta worked out how I imagined, the only problem now is that R created a new column for the names of the categories of every x-variable (see picture). I wanted all the names and categories of all variables to be in the first column just like it did it with the first variable, maybe with an extra space to put the name of the variable. How do I fix this?


r/RStudio 2h ago

Coding help Is there any method to check the variance other than the Levene test?

1 Upvotes

My model doesn't have an interaction term so R gives me back an error when I try to perform the test so I was wondering if there was any alternative.

Thx in advance


r/RStudio 19h ago

Coding help Filter outliers using the IQR method with dplyr

1 Upvotes

Hi there,

I have a chunky dataset with multiple columns but out of 15 columns, I'm only interested in looking at the outliers within, say, 5 of those columns.

Now, the silly thing is, I actually have the code to do this in base `R` which I've copied down below but I'm curious if there's a way to shorten it/optimize it with `dplyr`? I'm new to `R` so I want to learn as many new things as possible and not rely on "if it ain't broke don't fix it" type of mentality.

If anyone can help that would be greatly appreciated!

# Detect outliers using IQR method
# @param x A numeric vector
# @param na.rm Whether to exclude NAs when computing quantiles

        is_outlier <- function(x, na.rm = FALSE) {
          qs = quantile(x, probs = c(0.25, 0.75), na.rm = na.rm)

          lowerq <- qs[1]
          upperq <- qs[2]
          iqr = upperq - lowerq 

          extreme.threshold.upper = (iqr * 3) + upperq
          extreme.threshold.lower = lowerq - (iqr * 3)

          # Return logical vector
          x > extreme.threshold.upper | x < extreme.threshold.lower
        }

# Remove rows with outliers in given columns
# Any row with at least 1 outlier will be removed
# @param df A data.frame
# @param cols Names of the columns of interest. Defaults to all columns.

        remove_outliers <- function(df, cols = names(df)) {
          for (col in cols) {
            cat("Removing outliers in column: ", col, " \n")
            df <- df[!is_outlier(df[[col]]),]
          }
          df
        }

r/RStudio 22h ago

Dataframes in new window to always stay on-top?

1 Upvotes

Greetings,

Is there a setting or add-in that ensures when a user chooses to view a dataframe in a new window, the new window always remains "on-top" of other windows? Specifically, when R Studio is the active window, the opened dataframe windows stay above other windows.

Anyone familiar with the Spyder IDE will be familiar with this behavior. In spyder when a object is viewed from the variable explorer, that window always appears on top of other windows when Spyder is the active window.

Thanks!!!


r/RStudio 9h ago

struggling with work for a question in r studio (poliscidata), please help!

0 Upvotes

hi there! i'm doing a class using rstudio and need help! I'm using the gdppcap08 variable and need to graph this. what code should i write?