clear everything but one variable rm(list = ls()) [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • How can I remove all objects but one from the workspace in R?

    13 answers




I'm aware that rm(list = ls()) will clear my workspace.



I have a data frame x that I would like to preserve while removing everything else from memory. How can I do that?



rm(list = ls(!x)) #???









share|improve this question













marked as duplicate by Ronak Shah r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 9 at 18:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    0
    down vote

    favorite













    This question already has an answer here:




    • How can I remove all objects but one from the workspace in R?

      13 answers




    I'm aware that rm(list = ls()) will clear my workspace.



    I have a data frame x that I would like to preserve while removing everything else from memory. How can I do that?



    rm(list = ls(!x)) #???









    share|improve this question













    marked as duplicate by Ronak Shah r
    Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 9 at 18:18


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:




      • How can I remove all objects but one from the workspace in R?

        13 answers




      I'm aware that rm(list = ls()) will clear my workspace.



      I have a data frame x that I would like to preserve while removing everything else from memory. How can I do that?



      rm(list = ls(!x)) #???









      share|improve this question














      This question already has an answer here:




      • How can I remove all objects but one from the workspace in R?

        13 answers




      I'm aware that rm(list = ls()) will clear my workspace.



      I have a data frame x that I would like to preserve while removing everything else from memory. How can I do that?



      rm(list = ls(!x)) #???




      This question already has an answer here:




      • How can I remove all objects but one from the workspace in R?

        13 answers








      r






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 18:04









      Doug Fir

      5,2722780148




      5,2722780148




      marked as duplicate by Ronak Shah r
      Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 9 at 18:18


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Ronak Shah r
      Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 9 at 18:18


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          Try: rm(list = setdiff(ls(), x))



          Edit based on mickey's comment:



          Three objects in environment:



          ls()
          [1] "data_df" "list_ls" "vector_v"


          Remove data_df:



          rm(list = setdiff(ls(), "data_df"))
          ls()
          [1] "data_df"


          Vector of things to keep:



          toKeep_v <- c("list_ls", "vector_v")
          rm(list = setdiff(ls(), toKeep_v)
          ls()
          [1] "list_ls" "vector_v"





          share|improve this answer



















          • 5




            If x is the name of the data frame, it should be in quotes.
            – mickey
            Nov 9 at 18:08






          • 1




            While rm has NSE, setdiff doesn't so this will have unexpected results unless x is "x"
            – James
            Nov 9 at 18:10




















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          6
          down vote



          accepted










          Try: rm(list = setdiff(ls(), x))



          Edit based on mickey's comment:



          Three objects in environment:



          ls()
          [1] "data_df" "list_ls" "vector_v"


          Remove data_df:



          rm(list = setdiff(ls(), "data_df"))
          ls()
          [1] "data_df"


          Vector of things to keep:



          toKeep_v <- c("list_ls", "vector_v")
          rm(list = setdiff(ls(), toKeep_v)
          ls()
          [1] "list_ls" "vector_v"





          share|improve this answer



















          • 5




            If x is the name of the data frame, it should be in quotes.
            – mickey
            Nov 9 at 18:08






          • 1




            While rm has NSE, setdiff doesn't so this will have unexpected results unless x is "x"
            – James
            Nov 9 at 18:10

















          up vote
          6
          down vote



          accepted










          Try: rm(list = setdiff(ls(), x))



          Edit based on mickey's comment:



          Three objects in environment:



          ls()
          [1] "data_df" "list_ls" "vector_v"


          Remove data_df:



          rm(list = setdiff(ls(), "data_df"))
          ls()
          [1] "data_df"


          Vector of things to keep:



          toKeep_v <- c("list_ls", "vector_v")
          rm(list = setdiff(ls(), toKeep_v)
          ls()
          [1] "list_ls" "vector_v"





          share|improve this answer



















          • 5




            If x is the name of the data frame, it should be in quotes.
            – mickey
            Nov 9 at 18:08






          • 1




            While rm has NSE, setdiff doesn't so this will have unexpected results unless x is "x"
            – James
            Nov 9 at 18:10















          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          Try: rm(list = setdiff(ls(), x))



          Edit based on mickey's comment:



          Three objects in environment:



          ls()
          [1] "data_df" "list_ls" "vector_v"


          Remove data_df:



          rm(list = setdiff(ls(), "data_df"))
          ls()
          [1] "data_df"


          Vector of things to keep:



          toKeep_v <- c("list_ls", "vector_v")
          rm(list = setdiff(ls(), toKeep_v)
          ls()
          [1] "list_ls" "vector_v"





          share|improve this answer














          Try: rm(list = setdiff(ls(), x))



          Edit based on mickey's comment:



          Three objects in environment:



          ls()
          [1] "data_df" "list_ls" "vector_v"


          Remove data_df:



          rm(list = setdiff(ls(), "data_df"))
          ls()
          [1] "data_df"


          Vector of things to keep:



          toKeep_v <- c("list_ls", "vector_v")
          rm(list = setdiff(ls(), toKeep_v)
          ls()
          [1] "list_ls" "vector_v"






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 9 at 18:14

























          answered Nov 9 at 18:06









          Qwfqwf

          1488




          1488








          • 5




            If x is the name of the data frame, it should be in quotes.
            – mickey
            Nov 9 at 18:08






          • 1




            While rm has NSE, setdiff doesn't so this will have unexpected results unless x is "x"
            – James
            Nov 9 at 18:10
















          • 5




            If x is the name of the data frame, it should be in quotes.
            – mickey
            Nov 9 at 18:08






          • 1




            While rm has NSE, setdiff doesn't so this will have unexpected results unless x is "x"
            – James
            Nov 9 at 18:10










          5




          5




          If x is the name of the data frame, it should be in quotes.
          – mickey
          Nov 9 at 18:08




          If x is the name of the data frame, it should be in quotes.
          – mickey
          Nov 9 at 18:08




          1




          1




          While rm has NSE, setdiff doesn't so this will have unexpected results unless x is "x"
          – James
          Nov 9 at 18:10






          While rm has NSE, setdiff doesn't so this will have unexpected results unless x is "x"
          – James
          Nov 9 at 18:10





          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()