Is it possible to prevent R package conflicts while upgrading Ubuntu 16.04 LTS with R from CRAN to Ubuntu 18.04 LTS?

To run upgrade process from Ubuntu 16.04.7 LTS with R 3.4 from CRAN flawlessly one should do the following:

  1. Backup a list of installed R packages

    dpkg -l | grep "^ii  r-" | awk '{print $2}' > ~/r-debs.txt
    
  2. Remove CRAN r-cran.list APT sources file by

    sudo rm /etc/apt/sources.list.d/r-cran.list
    
  3. Remove R packages

    sudo apt-get autoremove $(cat r-debs.txt) --purge
    
  4. Install R packages back using versions from official repositories

    sudo apt-get install $(cat r-debs.txt)
    
  5. Install possible updates

    sudo apt-get update
    sudo apt-get dist-upgrade
    

    then reboot.

  6. Upgrade Ubuntu as usual using sudo do-release-upgrade or update-manager -c .

  7. Upgrade RStudio using command below:

    wget -c https://download1.rstudio.org/desktop/bionic/amd64/rstudio-1.4.1717-amd64.deb -O /tmp/rstudio.deb
    sudo apt-get install -y /tmp/rstudio.deb
    

The resulting Ubuntu 18.04.6 LTS system will have fully-functional R 3.4 from official repository.