mlammens / spThin

2 stars 7 forks source link

Error (error: In path.expand(path)) from spThin::thin(..., write.files = TRUE) resulting from long file names where a dataset with where "spec.col" has many levels #29

Open jeanKRS opened 1 year ago

jeanKRS commented 1 year ago

Hi,

I experienced a challenge saving files from thin( ) which I describe below and share the modification I made on the "thin.R" script changing how the files are named to both:

PROBLEM: saving thinned data by setting the option write.files = TRUE in “spThin::thin( …)

SOLUTION PROPOSED

Modify the “thin()” function’s source code by : “changing how the files names such that the name of the “species” is included in the file name. i.e

At “line 170”, add species name to the thinned output file, i.e Replacing:

csv.files <- paste( out.dir, out.base, "_thin", rep(1:n.csv), ".csv", sep="")

With:

csv.files <- paste( out.dir, out.base, "thin", gsub(" ", "", as.character(species)), rep(1:n.csv), ".csv", sep="")

This will ensure every file name is unique and line 185 which adds the “_new” to every subsequent file name will be unnecessary and can be removed.

RESULTS:

Regards