readRDS problem

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

readRDS problem

Sigbert Klinke
Hi,

I have two scripts, one creates a data structure (a list of data frames
+ some attributes) and saves it via saveRDS.

The second script reads the RDS file (outside of any function) and

data <- readRDS (name)

works, but

data <<- readRDS (name)

creates the error

Error: cannot change value of locked binding for 'data'

Any idea what goes wrong?

Thanks Sigbert

--
http://u.hu-berlin.de/sk
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: readRDS problem

Michael Dewey-3
Try calling it something other than data.

On 24/02/2016 09:26, Sigbert Klinke wrote:

> Hi,
>
> I have two scripts, one creates a data structure (a list of data frames
> + some attributes) and saves it via saveRDS.
>
> The second script reads the RDS file (outside of any function) and
>
> data <- readRDS (name)
>
> works, but
>
> data <<- readRDS (name)
>
> creates the error
>
> Error: cannot change value of locked binding for 'data'
>
> Any idea what goes wrong?
>
> Thanks Sigbert
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: readRDS problem

Sigbert Klinke
Hi,

thanks, using

test <<- readRDS (name)

it worked. But why?

Best Sigbert

Am 24.02.2016 um 10:39 schrieb Michael Dewey:

> Try calling it something other than data.
>
> On 24/02/2016 09:26, Sigbert Klinke wrote:
>> Hi,
>>
>> I have two scripts, one creates a data structure (a list of data frames
>> + some attributes) and saves it via saveRDS.
>>
>> The second script reads the RDS file (outside of any function) and
>>
>> data <- readRDS (name)
>>
>> works, but
>>
>> data <<- readRDS (name)
>>
>> creates the error
>>
>> Error: cannot change value of locked binding for 'data'
>>
>> Any idea what goes wrong?
>>
>> Thanks Sigbert
>>
>


--
http://u.hu-berlin.de/sk
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: readRDS problem

Erich Neuwirth
?data
will show you that data is a reserved word!


> On 24 Feb 2016, at 11:02, Sigbert Klinke <[hidden email]> wrote:
>
> Hi,
>
> thanks, using
>
> test <<- readRDS (name)
>
> it worked. But why?
>
> Best Sigbert
>
> Am 24.02.2016 um 10:39 schrieb Michael Dewey:
>> Try calling it something other than data.
>>
>> On 24/02/2016 09:26, Sigbert Klinke wrote:
>>> Hi,
>>>
>>> I have two scripts, one creates a data structure (a list of data frames
>>> + some attributes) and saves it via saveRDS.
>>>
>>> The second script reads the RDS file (outside of any function) and
>>>
>>> data <- readRDS (name)
>>>
>>> works, but
>>>
>>> data <<- readRDS (name)
>>>
>>> creates the error
>>>
>>> Error: cannot change value of locked binding for 'data'
>>>
>>> Any idea what goes wrong?
>>>
>>> Thanks Sigbert
>>>
>>
>
>
> --
> http://u.hu-berlin.de/sk <http://u.hu-berlin.de/sk>
> ______________________________________________
> [hidden email] <mailto:[hidden email]> mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html <http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

signature.asc (684 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: readRDS problem

Michael Dewey-3
In reply to this post by Sigbert Klinke
You need to do
help("<-")
for a full explanation but in brief when you do <- it assigns locally
and since it could not find data locally it makes it for you but when
you do <<- it tries its very best to find data somewhere. Since data is
the name of a function which the authors of R have locked it fails.

On 24/02/2016 10:02, Sigbert Klinke wrote:

> Hi,
>
> thanks, using
>
> test <<- readRDS (name)
>
> it worked. But why?
>
> Best Sigbert
>
> Am 24.02.2016 um 10:39 schrieb Michael Dewey:
>> Try calling it something other than data.
>>
>> On 24/02/2016 09:26, Sigbert Klinke wrote:
>>> Hi,
>>>
>>> I have two scripts, one creates a data structure (a list of data frames
>>> + some attributes) and saves it via saveRDS.
>>>
>>> The second script reads the RDS file (outside of any function) and
>>>
>>> data <- readRDS (name)
>>>
>>> works, but
>>>
>>> data <<- readRDS (name)
>>>
>>> creates the error
>>>
>>> Error: cannot change value of locked binding for 'data'
>>>
>>> Any idea what goes wrong?
>>>
>>> Thanks Sigbert
>>>
>>
>
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: readRDS problem

Duncan Murdoch-2
In reply to this post by Sigbert Klinke
On 24/02/2016 4:26 AM, Sigbert Klinke wrote:

> Hi,
>
> I have two scripts, one creates a data structure (a list of data frames
> + some attributes) and saves it via saveRDS.
>
> The second script reads the RDS file (outside of any function) and
>
> data <- readRDS (name)
>
> works, but
>
> data <<- readRDS (name)
>
> creates the error
>
> Error: cannot change value of locked binding for 'data'
>
> Any idea what goes wrong?

"data <<-" looks for an existing object named data in a parent
environment and changes it.  But the existing object is in the utils
namespace, and you're not allowed to change things there.

Duncan Murdoch

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: readRDS problem

Rolf Turner
In reply to this post by Erich Neuwirth
On 25/02/16 00:11, Erich Neuwirth wrote:
> ?data
> will show you that data is a reserved word!

That is simply not true.  There is no mention in help for data of "data"
being a reserved word.

Moreover, if "data" *were* a reserved word " <- " wouldn't work either.

Compare:

     data <- 42 # No problema.
and
     TRUE <- 42 # Throws an error; "TRUE" really *is* a reserved word.

The real explanation is more subtle; it involves "locking" and the
rather intricate behaviour of "<<-", which I do no claim to understand.

The best advice is: DON'T USE "<<-" !!!

See fortune("dumb down").

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.