Skip to content

Commit

Permalink
Merge branch 'main' into foward_met_files
Browse files Browse the repository at this point in the history
  • Loading branch information
John-C-Lin authored Oct 3, 2024
2 parents a92d9fd + 5b31c43 commit 6ab0091
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions r/dependencies.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ libs <- load_libs('dplyr',
'parallel',
'raster',
'rslurm',
'R.utils',
lib.loc = lib.loc)

# Load permute fortran dll for footprint matrix permutation
Expand Down
18 changes: 14 additions & 4 deletions r/src/link_files.r
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#' link_files symlinks files in exe/* to the target path
#' @author Ben Fasoli
#' link_files symlinks files to the target path using relative paths
#' @author Ben Fasoli & James Mineau
#'
#' @param from location of files
#' @param to location to create links
#'
#' @export

link_files <- function(from, to) {
files <- dir(from, full.names = T)
suppressWarnings(file.symlink(files, to))
require(R.utils)

# # Get all files in `from`
x <- lapply(from, list.files, full.names = T)
is_file <- sapply(x, function(x) length(x) == 0)
files <- c(from[is_file], unlist(x[!is_file]))

# Convert to paths relative to stilt_wd
relative_files <- R.utils::getRelativePath(files, to)

# Create the links
suppressWarnings(file.symlink(relative_files, to))
}
7 changes: 2 additions & 5 deletions r/src/simulation_step.r
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ simulation_step <- function(before_footprint = list(function() {output}),

# Save output object to compressed rds file and symlink to out/particles
saveRDS(output, output$file)

link <- file.path(output_wd, 'particles', basename(output$file))
suppressWarnings(file.symlink(output$file, link))
link_files(output$file, file.path(output_wd, 'particles'))

} else {
# If user opted to recycle existing trajectory files, read in the recycled
Expand Down Expand Up @@ -381,8 +379,7 @@ simulation_step <- function(before_footprint = list(function() {output}),
}

# Symlink footprint to out/footprints
link <- file.path(output_wd, 'footprints', basename(foot_file))
suppressWarnings(file.symlink(foot_file, link))
link_files(foot_file, file.path(output_wd, 'footprints'))

return(foot)
})
Expand Down

0 comments on commit 6ab0091

Please sign in to comment.