A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRDetach an R package (unload from session)

Introduction

  • Sometimes we want to remove a package from the current R session—similar to clearing a SAS LIBNAME with LIBNAME mylib CLEAR;
  • detach("package:pkg", unload = TRUE) removes an attached package from the search path and unloads its namespace
  • Check the current search path using search(); attached packages appear as "package:pkg"
  • Meta-packages like tidyverse attach several packages; detach them individually (loop through the tidyverse core packages)
  • Detaching can break objects depending on those functions; prefer a fresh R session for a clean slate during analysis pipelines