Save a data frame to a file addressing by name
<p>I have a data frame and a text variable containing the name of this data frame: </p>

<pre><code>adsl = data.frame(a=2, b=7, w=17)
ds_name = "adsl" 
</code></pre>

<p>I want to save my data frame from the workspace to the file named "dest_file". The code should be wrapped into a function get_r() 
with the data frame name as an argument:</p>

<pre><code>get_r(ds_name="adsl")
</code></pre>

<p>So I need to avoid using the explicit name "adsl" inside the code.</p>

<p>The following works almost correctly but the resulting data frame is called "temp_dataset", not "adsl":</p>

<pre><code>get_r = function(ds_name){
    temp_dataset = eval(parse(text=ds_name))
    save(temp_dataset, file = "dest_file")
}
</code></pre>

<p>Here is another option which works wrong (the text string is being saved, not the data frame):</p>

<pre><code>get_r = function(ds_name){
    save(ds_name, file = "dest_file")
}
</code></pre>

<p>What should I do to make R just execute</p>

<pre><code>save(adsl, file="dest_file") 
</code></pre>

<p>inside the function? Thank you for any help.</p>