WARNING: this function is deprecated, as directories of non-child objects can just be moved with regular methods (e.g., file.rename
) in the latest version of alabaster.
Pretty much as it says in the title.
This only works with non-child objects as children are referenced by their parents and cannot be safely moved in this manner.
moveObject(dir, from, to, rename.redirections = TRUE)
String containing the path to the staging directory.
String containing the path to a non-child object inside dir
, as used in acquireMetadata
.
This can also be a redirection to such an object.
String containing the new path inside dir
.
Logical scalar specifying whether redirections pointing to from
should be renamed as to
.
The object represented by path
is moved, along with any redirections to it.
A NULL
is invisibly returned.
This function will look around path
for JSON files containing redirections to from
, and update them to point to to
.
More specifically, if path
is a subdirectory, it will search in the same directory containing path
;
otherwise, it will search in the directory containing dirname(path)
.
Redirections in other locations will not be removed automatically - these will be caught by checkValidDirectory
and should be manually updated.
If rename.redirections=TRUE
, this function will additionally move the redirection files so that they are named as to
.
In the unusual case where from
is the target of multiple redirection files, the renaming process will clobber all of them such that only one of them will be present after the move.
In general, alabaster.* representations are safe to move as only the parent object's resource.path
metadata properties will contain links to the children's paths.
These links are updated with the new to
path after running moveObject
on the parent from
.
However, alabaster applications may define custom data structures where the paths are present elsewhere, e.g., in the data file itself or in other metadata properties.
If so, applications are reponsible for updating those paths to reflect the naming to to
.
tmp <- tempfile()
dir.create(tmp)
library(S4Vectors)
df <- DataFrame(A=1:10, B=LETTERS[1:10])
meta <- stageObject(df, tmp, path="whee")
writeMetadata(meta, tmp)
#> $type
#> [1] "local"
#>
#> $path
#> [1] "whee/simple.csv.gz"
#>
ll <- list(A=1, B=LETTERS, C=DataFrame(X=1:5))
meta <- stageObject(ll, tmp, path="stuff")
writeMetadata(meta, tmp)
#> $type
#> [1] "local"
#>
#> $path
#> [1] "stuff/list.json.gz"
#>
redirect <- createRedirection(tmp, "whoop", "whee/simple.csv.gz")
writeMetadata(redirect, tmp)
#> $type
#> [1] "local"
#>
#> $path
#> [1] "whoop"
#>
list.files(tmp, recursive=TRUE)
#> [1] "stuff/child-1/simple.csv.gz" "stuff/child-1/simple.csv.gz.json"
#> [3] "stuff/list.json.gz" "stuff/list.json.gz.json"
#> [5] "whee/simple.csv.gz" "whee/simple.csv.gz.json"
#> [7] "whoop.json"
moveObject(tmp, "whoop", "YAY")
list.files(tmp, recursive=TRUE)
#> [1] "YAY.json" "YAY/simple.csv.gz"
#> [3] "YAY/simple.csv.gz.json" "stuff/child-1/simple.csv.gz"
#> [5] "stuff/child-1/simple.csv.gz.json" "stuff/list.json.gz"
#> [7] "stuff/list.json.gz.json"