본문 바로가기

Contact English

【RStudio】 R 주요 트러블슈팅 [01-20]

 

R 주요 트러블슈팅 [01-20]

 

추천글 : 【R STUDIO】 R 스튜디오 목차 


 

1. Error: attempt to use zero-length variable name 

⑴ (grammar) 원인 : ``` 같은 문자가 있는 경우

 

 

2. Error: cannot allocate vector of size 4.9 Gb 

(system) 원인 : 프로세스가 메모리 한계를 초과한 경우

① 일반적으로 데이터 분석할 때 메모리 수요가 큼

② memory.limit으로 늘릴 수 있는 메모리는 PC의 램의 메모리를 초과할 수 없음

③ 작업관리자 → 성능 → 메모리

○ 총 메모리의 용량이 얼마인지 알 수 있음

○ 사용된 슬롯을 확인하고 추가로 램을 구입하는 게 하나의 방법이 될 수 있음

○ (주석) 데이터 분석을 한다고 하면 램 32 GB는 구비를 해야 할 듯

(grammar) 해결방법 (4.1.x 버전 혹은 그 이하)

memory.limit(size = 50000)

② # 컴퓨터의 최대 메모리 한계치 약 49GB로 높이기

③ 위 명령어는 윈도우에서만 적용 가능한 명령어

 (grammar) 해결방법 (4.2.x 이상 버전)

① "memory.limit() is no longer supported"라는 에러 메시지가 발생

② 이 경우 다음과 같이 R의 최대 메모리 한계치를 늘릴 수 있음 (레퍼런스)

 

library(usethis) 
usethis::edit_r_environ()

# Then, type "R_MAX_VSIZE=100Gb" and save .Renviron file.

 

③ 다만, Windows R 4.2.x 이상 버전에서는 자동으로 메모리를 늘리기 때문에 별도로 걱정할 필요는 없음 (레퍼런스)

④ 단, M1 맥북 에어 혹은 맥북 프로에서는 위와 같은 조치가 효과가 있음

 

 

3. Error: .onLoad failed in loadNamespace() for 'Cairo', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object 'Library Frameworks R.framework Versions 4.1 Resources library Cairo libs Cairo.so': dlopen(Library Frameworks R.framework Versions 4.1 Resources library Cairo libs Cairo.so, 0x0006): Library not loaded: opt X11 lib libXrender.1.dylib Referenced from: Library Frameworks R.framework Versions 4.1 Resources library Cairo libs Cairo.so Reason: tried: 'opt X11 lib libXrender.1.dylib' (no such file), 'Library Frameworks R.framework Resources lib libXrender.1.dylib' (no such file), 'Users parkjeongbin lib libXrender.1.dylib' (no such file), 'usr local lib libXrender.1.dylib' (no such file), 'usr lib libXrender.1.dylib' (no such file), 'lib libXrender.1.dylib' (no such file), 'Library Java JavaVirtualMachines jdk1.8.0_241.jdk Contents Home jre lib server libXrender.1.dylib' (no such file), 'var folders rt qbr8l3sj73zd871cg_jmqrcm0

(package) 원인 : 맥북에서 더이상 XQuartz를 제공하지 않음

(package) 해결방법 : https://www.xquartz.org/에서 XQuartz를 설치

⑶ 레퍼런스 : https://stackoverflow.com/questions/38952427/include-cairo-r-on-a-mac 

 

 

include cairo R on a mac

I'm trying to use 'Cairo' package in Rstudio, using the command install.packages('Cairo') and it goes through with no problem. I get this message- The downloaded binary packages are in /var/fold...

stackoverflow.com

 

 

4. ERROR: lazy loading failed for package ‘SeuratWrappers’

(package) 상황 : remotes::install_github('satijalab/seurat-wrappers')를 할 때 문제가 발생

 

> remotes::install_github('satijalab/seurat-wrappers')
Downloading GitHub repo satijalab/seurat-wrappers@HEAD
✔  checking for file ‘/private/var/folders/rt/qbr8l3sj73zd871cg_jmqrcm0000gn/T/Rtmp57GIIL/remotes77ad583c6cda/satijalab-seurat-wrappers-9652bdd/DESCRIPTION’ ...
─  preparing ‘SeuratWrappers’:
✔  checking DESCRIPTION meta-information ...
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
   Omitted ‘LazyData’ from DESCRIPTION
─  building ‘SeuratWrappers_0.3.0.tar.gz’
   
* installing *source* package ‘SeuratWrappers’ ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  there is no package called ‘R.utils’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
ERROR: lazy loading failed for package ‘SeuratWrappers’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/SeuratWrappers’
Warning message:
In i.p(...) :
  installation of package ‘/var/folders/rt/qbr8l3sj73zd871cg_jmqrcm0000gn/T//Rtmp57GIIL/file77ad110008a3/SeuratWrappers_0.3.0.tar.gz’ had non-zero exit status

 

(package) 원인 1. R.utils를 설치하지 않은 경우이므로 install.packages("R.utils")를 통해 해결

(package) 원인 2. https://github.com/satijalab/seurat-wrappers/issues/32 

 

 

Cannot install seurat-wrapers · Issue #32 · satijalab/seurat-wrappers

Hello, I am trying to install seurat-wrappers and running into an error, could you please help? devtools::install_github('satijalab/seurat-wrappers') Downloading GitHub repo satijalab/seura...

github.com

 

 

5. warning message: In normalizePath(path.expand(path), winslash, mustwork) : path [1]="C: Users ??? Documents" : 파일 이름, 디렉터리 이름 또는 볼륨 레이블 구문이 잘못되었습니다

(system) 원인 : 사용자명이 한글인 경우

(system) 해결방법 1. 사용자명을 영어로 바꾸는 방법 

(system) 해결방법 2. setwd 혹은 R studio를 통해 working directory path를 바꾸는 방법 

⑷ 이 이슈는 R에서는 크게 문제되지 않고, 다만 파이썬에서 문제가 됨 

 

 

6. there is no package called ‘ifnb.SeuratData’

(package) 해결방법 

 

install.packages("https://seurat.nygenome.org/src/contrib/ifnb.SeuratData_3.0.0.tar.gz", repos = NULL, type = "source")

 

⑵ 레퍼런스 : https://github.com/satijalab/seurat-data/issues/15

 

Cannot install ifnb dataset · Issue #15 · satijalab/seurat-data

When we tried to install the ifnb dataset, we got the following error: > InstallData('ifnb') trying URL 'http://seurat.nygenome.org/src/contrib/ifnb.SeuratData_3.1.0.tar.gz' Erro...

github.com

 

 

7. RStudio requires an existing installation of R in order to work. Please select the version of R to use. 

 (others) 해결방법 

 

【RStudio】 RStudio requires an existing installation of R in order to work. Please select the version of R to use.

RStudio requires an existing installation of R in order to work. Please select the version of R to use. 추천글 : 【RStudio】 R 주요 트러블슈팅 [01-20] 1단계. CRAN 설치 ⑴ 구글 검색창에 cran 입력 ⑵..

nate9389.tistory.com

 

 

8. The procedure entry point quadmath_snprintf could not be located in the dynamic link library C:\Users\USER\anaconda3\envs\MY_ENV\Lib\R\library\igraph\libs\x64\igraph.dll 

(package) 원인 : CRAN에서 제공한 igraph.dll은 Rlapack.dll가 quadmath_snprintf 함수를 제공하는 것을 전제로 하는데, Anaconda R은 무슨 이유에서인지 quadmath_snprintf  함수가 존재하지 않음  

(package) 해결방법 : conda-forge를 사용하여 igraph를 설치

⑶ 레퍼런스 : https://igraph.discourse.group/t/rterm-exe-entry-point-not-found/1326/3

 

Rterm.exe - Entry Point Not Found

I think the issue is that I have both installed on my system. I have the official R installed and that is version 4.1.0. Then I am working in an anaconda environment that has 4.1.3 installed, and that is where I am working in the above screenshot.

igraph.discourse.group

 

 

9. "에러: 크기가 13.3 GB인 벡터를 할당할 수 없습니다"

 (grammar) 해결방법 

 

【RStudio】 10강. 메모리 관리

10강. 메모리 관리 추천글 : 【RStudio】 R 스튜디오 목차 1. 메모리 정리 2. "에러: 크기가 13.3 GB인 벡터를 할당할 수 없습니다" a. GitHub 1. 메모리 정리 # 최종 데이터를 저장 save.image(file="temp..

nate9389.tistory.com

 

 

10. Error in .testForValidKeys(x, keys, keytype, fks) : None of the keys entered are valid keys for 'SYMBOL'. Please use the keys method to see a listing of valid arguments. 

(grammar) 문제 : human gene을 써야 하는 상황에 mouse gene을 쓴 경우, gene name 대신 ENSG, ENSMUSG 코드를 쓴 경우 등

(grammar) 해결방법 예시

 

# before
gene.df <- bitr(MY_GENE_LIST, 
                fromType = "SYMBOL",
                toType = c("ENSEMBL", "SYMBOL","ENTREZID"),
                OrgDb = org.Hs.eg.db) 
                
# after
gene.df <- bitr(MY_GENE_LIST, 
                fromType = "SYMBOL",
                toType = c("ENSEMBL", "SYMBOL","ENTREZID"),
                OrgDb = org.Mm.eg.db)

 

 

11. Error in library("clusterProfiler") :  there is no package called ‘clusterProfiler’

 (grammar) 문제 : 맥북에서 일부 패키지는 단순히 install.package, BiocManager::install만 하는 경우 문제를 종종 일으킴

(grammar) 해결방법 : RStudio 말고 CRAN에서 다음 코드를 실행 

 

install.packages('RSQLite', dependencies = TRUE, force = TRUE)
BiocManager::install('HDO.db', dependencies = TRUE, force = TRUE)
install.packages('graphlayouts', dependencies = TRUE, force = TRUE)
BiocManager::install('clusterProfiler', dependencies = TRUE, force = TRUE)

 

⑶ install.packages가 문제를 일으킬 때 일반적인 해결방법

① R studio 말고 CRAN에서 설치하기 

delete.packages('devtools') 후에 install.packages('devtools')를 하기

③ R studio를 다시 설치하기

④ 다른 컴퓨터 상에서 해보기

install.packages("devtools", repos = NULL, type = "source")와 같이 추가적인 argument를 사용하기

install.packages('devtools', dependencies = TRUE, force = TRUE)와 같이 추가적인 argument를 사용하기

⑦ 라이브러리 폴더 자체를 얻어서 원하는 PC 내 적절한 위치에 붙여넣는 방식

options(timeout=300)과 같은 코드를 통해 timeout 시간을 증가시킴

 

 

12. Error in sum(dim(scRNAseqData)): argument "b" is missing, with no default

 (grammar) 문제 : 다음 source 구문을 통해 함수를 불러왔는데, 이 과정에서 충돌이 생긴 것으로 보임

 

source("https://github.com/JB243/nate9389/blob/main/RStudio/A_Collection_of_Useful_Functions_in_RStudio.R?raw=true")

 

(grammar) 해결방법 : source로 함수를 불러오는 대신 일일히 필요한 함수를 정의해서 쓰는 게 바람직함

⑶ 비슷한 원인으로, "do.call" r argument "b" is missing, with no default 문제도 관찰됨

 

 

13. Error in AddMetaData.Seurat(br.sp, pathways) : 'col.name' must be provided for atomic metadata types (eg. vectors)

(grammar) 문제 : pathways가 double 형 변수 등 적절하지 않은 자료형인 경우

(grammar) 해결방법

 

pathways <- as.data.frame(pathways)
br.sp <- AddMetaData(br.sp, pathways)

 

 

14. Error in dimnames(x) <- dn : 'dimnames' applied to non-array

(grammar) 문제 : Seurat 객체의 colnames를 바꿀 수 있는 방법은 현재로서는 없음 (레퍼런스)

 (grammar) 해결방법 1. 다른 colnames를 가지는 Seurat 객체를 새로 정의 (레퍼런스)

 (grammar) 해결방법 2. orig.ident 부분을 바꿔서 비슷한 효과를 노릴 수 있음 

 

object$orig.ident <- c('C', 'A', 'B')

# reordering
object$orig.ident <- factor(x = object$orig.ident, levels = c('A', 'B', 'C'))

 

 

15. Error in tmp["CD34", ]: invalid or not-yet-implemented 'Matrix' subsetting

(grammar) 문제 : tmp 변수가 matrix가 아님. sparse matrix인 경우 이런 문제가 생길 수 있음

(grammar) 해결법 : tmp 변수를 matrix 형으로 형 변환

 

tmp = as.matrix(tmp)

 

 

16. Error in file(file, "rt") : invalid 'description' argument

(grammar) 원인 : Load10X_Spatial을 할 때 위 문제가 발생했는데, 그 원인은 spatial 폴더에 tissue_positions_list.csv와 tissue_positions.csv가 모두 있었기 때문이었음 (둘 중 하나만 있어야 함)

 

 

17. Error in intI(i, n = d[1L], dn[[1L]], give.dn = FALSE) : invalid character indexing

(grammar) 원인 1. Seurat 파이프라인에서 object@assays$RNA@dataobject@assays$RNA@scale.data에 다른 행렬 값을 덧씌우고 object_ = object[, c(1:10)]과 같이 subtyping 하는 경우 문제가 발생함

(grammar) 원인 2. pbmc_ = pbmc[gene_list, ]을 할 때 gene_list 안에 있는 언더바(_)가 에러를 일으킴

 예 1. C4B_2

 예 2. GTF2H2C_2

 예 3. XLOC_008559

 예 4. XLOC_009911

예 5. 18S_rRNA

 

 

18. Error in `rownames<-`(`*tmp*`, value = "Tumor_0-0Gy_1") : attempt to set 'rownames' on an object with no dimensions

(grammar) 원인 : factor형 변수는 특정 level의 값만 넣을 수 있는데, 그 이외의 값을 넣으려고 하는 경우 에러가 발생함

 (grammar) 해결방안

 

# Example
library(compGenomRData)
coldata_file  <- system.file ("extdata/rna-seq/SRP029880.colData.tsv", package = "compGenomRData")
colData <- read.table(coldata_file, header = T, sep = '\t', 
                      stringsAsFactors = TRUE)
colData$source_name <- as.character(colData$source_name)
colData$group <- as.character(colData$group)

## Exemplary edition of the given data
colData[1,1] = "A"
colData[1,2] = "B"

colData$source_name <- as.factor(colData$source_name)
colData$group <- as.factor(colData$group)

 

레퍼런스 

 

How to Fix in R: invalid factor level, NA generated - Statology

This tutorial explains how to avoid the following warning message in R: invalid factor level, NA generated.

www.statology.org

 

 

19. Warning message: In read.table(file = file, header = header, sep = sep, quote = quote,  : incomplete final line found by readTableHeader on 'my_data.csv'

(grammar) 해결방법 : suppressWarnings를 쓰면 됨  

 

# Before
df <- read.csv('my_data.csv')

# After
df <- suppressWarnings(read.csv('my_data.csv'))

 

레퍼런스 

 

 

20. 맥북에서 RStudio를 켰을 때 빈 화면만 나타나는 경우

 문제 상황

 

 

 (system) 원인 : RStudio workplace에서 기본 폴더 이외에도 한글 이름으로 된 폴더가 있는 경우 

 

 

 (system) 해결방법 : RStudio workplace에서 기본 폴더 이외에 폴더명을 모두 영어로 변경 (기본 폴더는 변경이 안 되므로 그대로)

 

 

입력: 2022.01.29 17:33

수정: 2023.06.02 18:13