R related Seurat non-zero exit status 00LOCK-Seurat

I use Posit on AWS sagemaker. I am trying to install the Seurat package for scRNA analysis. I tried to install the package using

remotes::install_github("satijalab/seurat","v5.0.1")

I am getting this error

remotes::install_github("satijalab/seurat","v5.0.1")
Using github PAT from envvar GITHUB_PAT
Downloading GitHub repo satijalab/seurat@v5.0.1
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

1: All                                
2: CRAN packages only                 
3: None                               
4: matrixStats (1.1.0 -> 1.2.0) [CRAN]

Enter one or more numbers, or an empty line to skip updates: 1
matrixStats (1.1.0 -> 1.2.0) [CRAN]
Installing 1 packages: matrixStats
Installing package into ‘/home/sagemaker-user/R/x86_64-pc-linux-gnu-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/matrixStats_1.2.0.tar.gz'
Content type 'application/x-gzip' length 210870 bytes (205 KB)
==================================================
downloaded 205 KB

ERROR: failed to lock directory ‘/home/sagemaker-user/R/x86_64-pc-linux-gnu-library/4.2’ for modifying
Try removing ‘/home/sagemaker-user/R/x86_64-pc-linux-gnu-library/4.2/00LOCK-matrixStats’

The downloaded source packages are in
	‘/tmp/RtmpowPYMX/downloaded_packages’
── R CMD build ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔  checking for file ‘/tmp/RtmpowPYMX/remotesd5f58c3c74e/satijalab-seurat-6b89679/DESCRIPTION’ (344ms)
─  preparing ‘Seurat’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  installing the package to process help pages
─  cleaning src (1m 14.7s)
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘Seurat_5.0.1.tar.gz’
   
Installing package into ‘/home/sagemaker-user/R/x86_64-pc-linux-gnu-library/4.2’
(as ‘lib’ is unspecified)
ERROR: failed to lock directory ‘/home/sagemaker-user/R/x86_64-pc-linux-gnu-library/4.2’ for modifying
Try removing ‘/home/sagemaker-user/R/x86_64-pc-linux-gnu-library/4.2/00LOCK-Seurat’
Warning messages:
1: In i.p(...) :
  installation of package ‘matrixStats’ had non-zero exit status
2: In i.p(...) :
  installation of package ‘/tmp/RtmpowPYMX/filed5fe5e7012/Seurat_5.0.1.tar.gz’ had non-zero exit status

I tried to remove the 00LOCK-Seurat as well in the terminal but getting another error
'' Device or resource busy"

please help.

The directory of your package library is probably on a shared network drive and another process (or container/VM/etc.) is locking that file, or some other network driver issue is happening.

You can try to rename that file instead of deleting it, or you can try to stop all processes (containers/etc.) that are using that package library, and then try the installation again.

I did restart the instance. Also, I did rename the directory as suggested, even then it is not working.

Also, I do see that there are some sessions in the workbench which are not going away ever after force quitting them (status is shutting down since yesterday).

I don't know if there is a way to force-eliminate those sessions, if you can't do that I suggest you ask your Workbench support.

Also, if there is a 'workbench' tag here on community.rstudio.com, I suggest you add it to this question, so the right people see it.

Also, just to unlock you, you can try using R 4.3.x, which will use a different package library directory.