2024-07-17 Shell后台运行

Rscript后台运行

  1. nohup Rscript scRNA.R > my_log.out 2>&1 &

scRNA.R 如下:
######## Load necessary library
library(dplyr)

######## Read the data from a CSV file
data <- read.csv("input.csv")

######## Calculate the mean and standard deviation of each numeric column
stats <- data %>%
summarise_all(list(mean = mean, sd = sd), na.rm = TRUE)

######## Write the results to a new CSV file
write.csv(stats, "output.csv")

  1. 增加命令行参数
    nohup Rscript scRNA2.R input.csv output.csv > my_log.out 2>&1 &

scRNA2.R 如下:
######## Load necessary library
library(dplyr)

######## Get the command line arguments
args <- commandArgs(trailingOnly = TRUE)

######## Read the data from the input CSV file
data <- read.csv(args[1])

######## Calculate the mean and standard deviation of each numeric column
stats <- data %>%
summarise_all(list(mean = mean, sd = sd), na.rm = TRUE)

######## Write the results to the output CSV file
write.csv(stats, args[2])

#######--args[1]是输入文件的名称,args[2]是输出文件的名称

参考:运行耗时比较长的代码就需要后台运行了-腾讯云开发者社区-腾讯云 (tencent.com)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.R语言、Rstudio简介 11:50 CRAN官方网站 Task views 比如我想做生存分析 但是我不知...
    小梦游仙境阅读 4,241评论 2 8
  • 对于习惯使用sql的同学,etl切换成用R,如何能够很快的对应上手呢? 直接上代码教程: 1. 获取数据源 R设置...
    AJane阅读 5,510评论 0 1
  • R数据科学### 20200919 8:30 raining#### shif+enter 换行 planes ...
    miki1823阅读 4,671评论 0 2
  • 4.2 dplyr包简介 dplyr包提供了一组函数,用于有效地操作R中的数据集。dplyr包是下一代“plyr”...
    ZMQ要加油呀阅读 5,189评论 0 0
  • 第一课:安装与基本操作 R的扩展包在R官网CRAN;另外,R官网还包含很多扩展资料,包括源代码,手册,FAQ,推荐...
    lizi_sjtu阅读 3,923评论 0 0