简体   繁体   中英

How to clear the console automatically when R start?

I added some packages in the defaultPackages of Rprofile.site file using .First function, however, there are some warning messages during the R starting, I wonder how to clear the console automatically or suppress these messages when R start. I added cat("\\014") , but it doesn't work. I know Ctrl+L could be used to clear the console after R start.

.First <- function(){
options(defaultPackages=c(getOption("defaultPackages"),"tidyverse","pacman"))
cat("\014")
}

The main messages are from tidyverse package.

- Attaching packages --------------------------------------- tidyverse 1.2.1 --
√ ggplot2 3.2.0     √ purrr   0.3.2
√ tibble  2.1.3     √ dplyr   0.8.3
√ tidyr   0.8.3     √ stringr 1.4.0
√ readr   1.3.1     √ forcats 0.4.0
-- Conflicts ------------------------------------------ 
tidyverse_conflicts() --
x lubridate::as.difftime() masks base::as.difftime()
x lubridate::date()        masks base::date()
x dplyr::filter()          masks stats::filter()
x lubridate::intersect()   masks base::intersect()
x dplyr::lag()             masks stats::lag()
x lubridate::setdiff()     masks base::setdiff()
x lubridate::union()       masks base::union()

You can try to run the following command:

cat("\033[2J\033[0;0H")

This works for some working environments / terminals. For example, it works for my R standalone running in a terminal, but not in rstudio.

The following works in rstudio, though:

cat("\f")

(I just saw that this does not work for you – it is the same as cat("\\014") . So maybe the first one does).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM