LNCD

Table of Contents

  • LNCD Home
  • Administration
  • Notebooks
  • Journal Club Presentations
  • Publications
  • Current Projects
  • Completed Projects
  • Current Grants
  • Datasets by Project
  • Brain ROIs and Measures
  • ️Tools And Methods
  • Big Data
  • RA Homepage
  • Recent Changes
  • Maintenance
  • Site Map
  • Random Page
LNCD
Admin » GNU R

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:r [2023/10/20 13:02] – na.action=na.exclude willtools:r [2025/07/22 17:01] (current) – [na.action] vid79
Line 4: Line 4:
 The [[https://www.r-project.org/|GNU R programming language]] is often paired with [[https://posit.co/download/rstudio-desktop/|posit's RStudio Desktop IDE]] and a suit of libraries (language packages) known as [[:tools:tidyverse|tidyverse]] (includes ''dplyr'' and ''ggplot2'').  The [[https://www.r-project.org/|GNU R programming language]] is often paired with [[https://posit.co/download/rstudio-desktop/|posit's RStudio Desktop IDE]] and a suit of libraries (language packages) known as [[:tools:tidyverse|tidyverse]] (includes ''dplyr'' and ''ggplot2''). 
  
-You can also find a web interface to [[http://rhea.wpic.upmc.edu:8787/|Rstudio on rhea]] (also [[:admin:remoteaccess|Remote Access]]).+You can also find a web interface to [[http://rhea.wpic.upmc.edu:8787/|Rstudio on rhea]] (also [[:admin:remoteaccess]]).
  
 [[:tools:tutorials|Tutorials]] contains additional resources. [[:tools:tutorials|Tutorials]] contains additional resources.
  
 +See [[:tools:r:issues]] for log of debugged problems.
 ===== Notes ===== ===== Notes =====
-==== na.action ====+==== na.action for residual ====
 When adding module residuals back to a dataframe, you need ''residuals()'' to return the same length as the input data.frame. use ''lm(na.action=na.exclude)''. When adding module residuals back to a dataframe, you need ''residuals()'' to return the same length as the input data.frame. use ''lm(na.action=na.exclude)''.
  
Line 17: Line 18:
 d <-  data.frame(x=c(1:4,NA),y=1:5); d <-  data.frame(x=c(1:4,NA),y=1:5);
 m <- lm(x~y,d,na.action=na.exclude); m <- lm(x~y,d,na.action=na.exclude);
-nrow(d);  +nrow(d);              # 5 
-length(m$residuals);  +length(m$residuals);  # 4 
-length(residuals(m)) +length(residuals(m))  # 5
-   [1] 5 +
-   [1] 4 +
-   [1] 5+
 </code> </code>
  
Line 32: Line 30:
  
  
 +==== MASS::select vs dplyr::select  ====
 +If you load MASS after dplyr, ''select'' will be ''MASS::select'' not ''dplyr::select'' and you're likely to encounter hard-to-debug errors about unused arguments
  
 +> Error in select ...  : unused arguments
 + 
 +**solutions** include 
 +  - load MASS first
 +  - force select to be ''dplyr'''s version, or 
 +  - unload MASS if you don't need it
 +
 +<code>
 +# load mass before dplyr to have 'select' be from dplyr
 +library(MASS)
 +library(dplyr)
 +
 +# force which select (if MASS was already loaded after dplyr and overwrite the function)
 +select <- dplyr::select
 +
 +# or unload MASS
 +detach("package:MASS", unload=TRUE)
 +
 +# check to see
 +environment(select) # if "MASS", you're in for a bad time
 +</code>
 ===== Backlinks ===== ===== Backlinks =====
  
  
 {{backlinks>.}} {{backlinks>.}}