一、安装monocle3包
monocle3 是一个用于分析单细胞转录组数据的 R 包。它提供了强大的工具来进行细胞轨迹分析、细胞类型标注以及其他高级单细胞数据分析功能。下面是如何在你的系统中安装 monocle3 包的详细步骤
这有一个参考,如何安装monocle3,BiocManager::install("monocle3")问题解决
如何安装monocle3,BiocManager::install("monocle3")问题解决 (qq.com)
install.packages("monocle3")
BiocManager::install("monocle3")
Error in library(monocle3) : there is no package called ‘monocle3’
这个错误提示说明 monocle3 包尚未成功安装。我们可以通过确保安装过程无误来解决这个问题。以下是详细的步骤:
1. 安装必要的依赖包
首先,确保你已经安装了 remotes 包,因为我们将使用它来安装 monocle3 包。
install.packages("remotes")
2. 使用 remotes 安装 monocle3
接下来,使用 remotes 包从 GitHub 安装 monocle3 包:
remotes::install_github("cole-trapnell-lab/monocle3")
这将从 GitHub 下载和安装最新版本的 monocle3 包。
3. 安装 sf 包的依赖项
如果你在安装 monocle3 之前遇到 sf 包的依赖问题,请确保你已经安装了 sf 包及其所有依赖项。以下是在 Ubuntu 系统上常见的步骤:
如果你在 R 控制台中,可以使用 system() 函数来安装必要的系统依赖项
system("sudo apt-get update")
system("sudo apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev")
安装 R 包
install.packages("units", dependencies = TRUE)
install.packages("sf", dependencies = TRUE, type = "source")
4. 安装 monocle3 所有依赖包
确保安装 monocle3 之前所需的所有依赖包:
install.packages(c("BiocManager", "devtools"))
BiocManager::install(c("BiocGenerics", "DelayedArray", "DelayedMatrixStats", "limma", "S4Vectors", "SingleCellExperiment", "SummarizedExperiment", "batchelor"))
5. 再次尝试安装 monocle3
在安装完所有依赖包之后,再次尝试安装 monocle3:
remotes::install_github("cole-trapnell-lab/monocle3")
6. 加载并验证 monocle3
安装完成后,加载 monocle3 包并验证它是否成功安装:
library(monocle3)
在安装sf包步骤又报错:
install.packages("units", dependencies = TRUE)
install.packages("sf", dependencies = TRUE, type = "source")
error: ‘ret’ was not declared in this scope
713 | return ret;
| ^~~
make: *** [/usr/lib/R/etc/Makeconf:200: gdal.o] Error 1
ERROR: compilation failed for package ‘sf’
* removing ‘/usr/local/lib/R/site-library/sf’
ERROR: dependency ‘sf’ is not available for package ‘leafem’
* removing ‘/usr/local/lib/R/site-library/leafem’
ERROR: dependency ‘sf’ is not available for package ‘leafpop’
* removing ‘/usr/local/lib/R/site-library/leafpop’
ERROR: dependency ‘sf’ is not available for package ‘lwgeom’
* removing ‘/usr/local/lib/R/site-library/lwgeom’
ERROR: dependency ‘sf’ is not available for package ‘stars’
* removing ‘/usr/local/lib/R/site-library/stars’
ERROR: dependencies ‘sf’, ‘lwgeom’, ‘stars’ are not available for package ‘tmaptools’
* removing ‘/usr/local/lib/R/site-library/tmaptools’
ERROR: dependencies ‘leafem’, ‘leafpop’, ‘sf’ are not available for package ‘mapview’
* removing ‘/usr/local/lib/R/site-library/mapview’
ERROR: dependencies ‘tmaptools’, ‘sf’, ‘stars’, ‘leafem’ are not available for package ‘tmap’
* removing ‘/usr/local/lib/R/site-library/tmap’
从错误日志中可以看出,编译 sf 包时出现了 ‘ret’ was not declared in this scope 的错误。这通常意味着编译器找不到某个变量的定义,可能是由于缺少某些头文件或库版本不兼容的问题。
以下是一些可能的解决方案:
1.更新系统库
确保所有相关的系统库(GDAL、GEOS、PROJ)都已更新到最新版本。
对于 Ubuntu/Debian 系统
首先,添加必要的 PPA 来获取最新版本的 GDAL、GEOS 和 PROJ:
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
然后安装或更新相关库:
sudo apt-get install -y gdal-bin libgdal-dev libgeos-dev libproj-dev libudunits2-dev libsqlite3-dev libcurl4-openssl-dev libssl-dev build-essential
2.手动编译和安装 GDAL 和 PROJ
如果系统包管理器提供的版本较旧,可以考虑手动编译和安装最新版本的 GDAL 和 PROJ。
安装 PROJ
wget https://download.osgeo.org/proj/proj-7.2.1.tar.gz
tar -xvf proj-7.2.1.tar.gz
cd proj-7.2.1
./configure
make
sudo make install
安装 GDAL
sh
wget https://download.osgeo.org/gdal/3.2.1/gdal-3.2.1.tar.gz
tar -xvf gdal-3.2.1.tar.gz
cd gdal-3.2.1
./configure
make
sudo make install
3.设置 R 环境变量
确保 R 可以找到正确的编译器和库路径:
Sys.setenv("PKG_CONFIG_PATH" = "/usr/local/lib/pkgconfig:/usr/lib/pkgconfig")
Sys.setenv("LD_LIBRARY_PATH" = "/usr/local/lib:/usr/lib")
4.重新安装 units 包
有时候 units 包的问题会导致 sf 包无法安装。先尝试重新安装 units 包。
install.packages("units", dependencies = TRUE, type = "source")
5.手动安装 sf 包
手动下载 sf 包的源代码并安装:
wget https://cran.r-project.org/src/contrib/sf_1.0-0.tar.gz
在 R 控制台中手动安装:
install.packages("sf_1.0-0.tar.gz", repos = NULL, type = "source", verbose = TRUE)
也试了
安装install.packages("sf")报错解决办法.checking GDAL: checking whether PROJ
安装install.packages("sf")报错解决办法.checking GDAL: checking whether PROJ | 生信圆桌 (tebteb.cc)
仍然报错,哭了
error: ‘ret’ was not declared in this scope
713 | return ret;
| ^~~
最后遇见了
remotes::install_github(repo = "r-spatial/sf")
成功了
Downloading GitHub repo r-spatial/sf@HEAD
Running `R CMD build`...
* checking for file ‘/tmp/RtmpMNsu0s/remotes10c4f632fb6/r-spatial-sf-a07adc6/DESCRIPTION’ ... OK
* preparing ‘sf’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* running ‘cleanup’
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘sf_1.0-18.tar.gz’
Installing package into ‘/cloud/lib/x86_64-pc-linux-gnu-library/4.4’
(as ‘lib’ is unspecified)
* installing *source* package ‘sf’ ...
** using staged installation
configure: CC: gcc
configure: CXX: g++ -std=gnu++17
checking for gdal-config... /usr/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 3.0.4
checking GDAL version >= 2.0.1... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for gdal.h... yes
checking GDAL: linking with --libs only... yes
checking GDAL: /usr/share/gdal/pcs.csv readable... no
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available for running:... yes
configure: GDAL: 3.0.4
configure: pkg-config proj exists, will use it
configure: using proj.h.
configure: PROJ: 6.3.1
checking PROJ: checking whether PROJ and sqlite3 are available for linking:... yes
checking for geos-config... /usr/bin/geos-config
checking geos-config usability... yes
configure: GEOS: 3.8.0
checking GEOS version >= 3.4.0... yes
checking for geos_c.h... yes
checking geos: linking with -L/usr/lib/x86_64-linux-gnu -lgeos_c... yes
configure: Package CPP flags: -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include
configure: Package LIBS: -lproj -L/usr/lib -lgdal -L/usr/lib/x86_64-linux-gnu -lgeos_c
configure: creating ./config.status
config.status: creating src/Makevars
** libs
using C++ compiler: ‘g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0’
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c bbox.cpp -o bbox.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c gdal.cpp -o gdal.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c gdal_geom.cpp -o gdal_geom.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c gdal_read.cpp -o gdal_read.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c gdal_read_stream.cpp -o gdal_read_stream.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c gdal_utils.cpp -o gdal_utils.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c gdal_write.cpp -o gdal_write.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c geos.cpp -o geos.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c hex.cpp -o hex.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c mdim.cpp -o mdim.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c ops.cpp -o ops.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c polygonize.cpp -o polygonize.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c proj.cpp -o proj.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c proj_info.cpp -o proj_info.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c raster2sf.cpp -o raster2sf.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c sfc-sfg.cpp -o sfc-sfg.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c signed_area.cpp -o signed_area.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c stars.cpp -o stars.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c wkb.cpp -o wkb.o
g++ -std=gnu++17 -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/usr/include/gdal -I/usr/include -I'/cloud/lib/x86_64-pc-linux-gnu-library/4.4/Rcpp/include' -I/usr/local/include -fpic -g -O2 -c zm_range.cpp -o zm_range.o
g++ -std=gnu++17 -shared -L/opt/R/4.4.1/lib/R/lib -L/usr/local/lib -o sf.so RcppExports.o bbox.o gdal.o gdal_geom.o gdal_read.o gdal_read_stream.o gdal_utils.o gdal_write.o geos.o hex.o mdim.o ops.o polygonize.o proj.o proj_info.o raster2sf.o sfc-sfg.o signed_area.o stars.o wkb.o zm_range.o -lproj -L/usr/lib -lgdal -L/usr/lib/x86_64-linux-gnu -lgeos_c -L/opt/R/4.4.1/lib/R/lib -lR
installing to /cloud/lib/x86_64-pc-linux-gnu-library/4.4/00LOCK-sf/00new/sf/libs
** R
** demo
** inst
** byte-compile and prepare package for lazy loading
in method for ‘dbWriteTable’ with signature ‘"PostgreSQLConnection","character","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘dbDataType’ with signature ‘"PostgreSQLConnection","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘coerce’ with signature ‘"Spatial","sf"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"Spatial","sfc"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sf","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sfc","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"XY","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"crs","CRS"’: no definition for class “CRS”
in method for ‘coerce’ with signature ‘"sgbp","sparseMatrix"’: no definition for class “sparseMatrix”
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (sf)
再安装monocle3包就可以了。