RStudio can't seem to run basic commands fast enough, no stop sign icon or "<"

Hi, this is my first post so bear with me haha.

I am having trouble running basic lines of code on RStudio. I have this script I am trying to run in RStudio and after a few code executions it seemingly conks out. There is no stop sign to indicate that it is running and it takes exceedingly long to have the "<" appear again. I had suspected that it might have to do with the size of the file i was initially loading in or the memory load but neither of those seem to be the problem. For instance, after the console "conks out" when I try to run loops, the whole loop won't appear in the console, only the first line. Additionally, simple commands like initialization of an object x = 4 for instance take way too long. I attached another photo to show what I mean. I am really lost on how to fix this because not 3 months ago this script worked perfectly fine and now all of a sudden it is not working even with no changes to the script. I tried updating, reinstalling RStudio, using a completely different system and nothing has worked. It seems like there is a massive delay between the running of the command and it actually executing. If anyone can help with this I'd be really appreciative.

One more thing, not much memory is being taken up here from what I can see so I am not sure what is going wrong.

Another strange thing happened. While waiting for the code in the first photo to run, I noticed that it finally showed the rest of the loop, along with a line of code that isnt in the script and that I didnt write but it is running anyway. Here's another photo. If you look at the top left, you will see that I was searching for the line "View(sortedProtData)" to find the line that was run right after the loop and its nowhere on my script. If someone has any info as to why this is happening please help.

You don't need loops, we can operate on entire columns at once (because they're vectors)

# load as a data.table
df <- fread("MethMatrixCG-HumanBLoodFitness96_10-100.csv")
# remove PFitness_ from the label" column
df$label <- gsub("PFitness_", "", df$label)
# convert sampleID to integer
df$sampleID <- as.integer(df$sampleID, na.rm = FALSE)
# sort the data by sampleID
df <- df[order(sampleID)]
# make sure it looks OK
head(df)
# write to a file
fwrite(df, file = "my_data.csv")

alternatively, you could take the tidyverse approach:

library(tidyverse)
# load 
read_csv("MethMatrixCG-HumanBLoodFitness96_10-100.csv") %>% 
  mutate(
    # remove PFitness_ from the label" column
    label = str_remove(label, "PFitness_"),
    # convert sampleID to integer
    sampleID = as.integer(sampleID)
    ) %>% 
  # sort the data by sampleID and assign the result to df 
  arrange(sampleID) -> df

# write to a file
write_csv(df, "my_tibble.csv", na = "NA")

Last, but not least, for the love of everything that is good and holy, stop using setwd and adopt a project-oriented workflow: Project-oriented workflow

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.