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)) #???
r
marked as duplicate by Ronak Shah
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.
add a comment |
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)) #???
r
marked as duplicate by Ronak Shah
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.
add a comment |
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)) #???
r
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
r
asked Nov 9 at 18:04
Doug Fir
5,2722780148
5,2722780148
marked as duplicate by Ronak Shah
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
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.
add a comment |
add a comment |
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"
5
If x is the name of the data frame, it should be in quotes.
– mickey
Nov 9 at 18:08
1
Whilerm
has NSE,setdiff
doesn't so this will have unexpected results unlessx
is"x"
– James
Nov 9 at 18:10
add a comment |
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"
5
If x is the name of the data frame, it should be in quotes.
– mickey
Nov 9 at 18:08
1
Whilerm
has NSE,setdiff
doesn't so this will have unexpected results unlessx
is"x"
– James
Nov 9 at 18:10
add a comment |
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"
5
If x is the name of the data frame, it should be in quotes.
– mickey
Nov 9 at 18:08
1
Whilerm
has NSE,setdiff
doesn't so this will have unexpected results unlessx
is"x"
– James
Nov 9 at 18:10
add a comment |
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"
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"
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
Whilerm
has NSE,setdiff
doesn't so this will have unexpected results unlessx
is"x"
– James
Nov 9 at 18:10
add a comment |
5
If x is the name of the data frame, it should be in quotes.
– mickey
Nov 9 at 18:08
1
Whilerm
has NSE,setdiff
doesn't so this will have unexpected results unlessx
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
add a comment |