natverse / flycircuit

R package flycircuit

Home Page:https://natverse.github.io/flycircuit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

load_fcdata can blast pre-existing objects

jdmanton opened this issue · comments

Currently, load_fcdata() returns NULL if the data is already loaded. This can cause objects to be blasted away by doing:

foo <- load_fcdata('foo')
# some other code
foo <- load_fcdata('foo')

Would it not be better to return the existing object instead?

This arises in part from a difference between the behaviour of readRDS and load. readRDS returns the object, load returns a character vector. This means that load_fcdata needs to be used differently according to the type of object.

# foo.rds
foo <- load_fcdata('foo')
# bar.rda, bar will be placed in .GlobalEnv environment by default
load_fcdata('bar')

I guess if the object exists we could do:

invisible(get(data))

or try to figure out whether the object came from an rds file or an rda file and adjust behaviour accordingly.

A more fundamental behaviour would be to change the behaviour when it loads something, returning the object rather than inserting it into the global environment by default. The only downside is that there is a small convenience factor in not having to specify the name of the object twice and 2) being able to load multiple objects from an rda file in one go.