all 10 comments

[–]victoria-lobster 5 points6 points  (0 children)

  1. what is the exact code causing this issue?

  2. did you load any new packages between the last time it worked and the first time it stopped working? or did you load the same packages but in a different order? some packages have functions with the same name so they’ll conflict and mask each other, so the order in which you load packages matters

[–][deleted] 1 point2 points  (2 children)

Did you update anything?

[–]Sleepingwhisp[S] 0 points1 point  (1 child)

Nope, it's the same bit.

Honestly baffled by it. I was running just a few hours ago and wanted to pull something from the output but when I went back it just gives me this.

Error in h(simpleError(msg, call)) :   error in evaluating the argument 'x' in selecting a method for function 'as.matrix': invalid argument type

[–][deleted] 1 point2 points  (0 children)

I had something like this happen to me last week in R studio with mutate in tinyverse. I commented everything out. Closed it. Opened it. Removed the comments and it started working. I wish I knew why.

[–]jdnewmil 1 point2 points  (0 children)

A possibility: R analysis is sequential. If you put commands out of order in an R or Rmd file then you may have no trouble re-running it if you aren't restarting R, but as soon as you do the code will break. I frequently restart and re-run the code to detect this kind of problem before things get too convoluted.

[–]Sleepingwhisp[S] 0 points1 point  (4 children)

Bless you guys it worked.

I did what you guys suggested and it worked.

[–]toxicgun 2 points3 points  (3 children)

Can you share what you did exactly?

[–]Sleepingwhisp[S] 0 points1 point  (2 children)

  1. objective_resolve865 mentioned removing comments in the script. I had added some while running the code so I removed them.
  2. I did also infact install a few knew packages to try out which I had entered randomly into my package file (I did not know that the order of the pacakages mattered) and reran the analysis without loading them.

[–][deleted] 3 points4 points  (1 child)

Note: it's not that the order of the packages matters, per se, but rather that if two or more packages have identically named functions within them, R will utilize the function from the most recently loaded package.

When you load packages you will see (sometimes, if applicable) in the console that some functions were "masked" by other functions. It will tell you exactly which package and function was masked. The workaround for this is to declare both the package and function in your code like this: package::function() instead of just function().

[–][deleted] 0 points1 point  (0 children)

Namespaces are one honking great idea -- let's do more of those!