Skip to contents

Remove Java wrappers stored in field "w" from the instr.descriptor metadata attribute of spectral objects and of members of collections of spectra loaded from R data files, saving them using their original name and location, after renaming the original files to serve as backups.

Usage

files_rm_jwrapper(
  path = ".",
  pattern = "\\.spct\\.[Rr]da",
  recursive = TRUE,
  date.limit = NULL,
  trim.descriptor = TRUE,
  save.files = FALSE,
  verbose = getOption("photobiology.verbose", default = FALSE)
)

Arguments

path

character Vector of full path names; the default corresponds to the working directory. Tilde expansion (see path.expand()) is performed. See list.files() for details.

pattern

character An optional regular expression. Only file names which match the regular expression will be returned. See list.files() for details.

recursive

logical Should the listing recurse into directories?

date.limit

POSIXct Files with more recent creation dates are skipped assuming they have been created with 'ooacquire' (>= 0.2.5 2022-09-30).

trim.descriptor

logical If TRUE apply trimInstrDesc() instead of rm_jwrapper() to spectral objects containing data in physical units. rm_jwrapper() is always used for objects containing sensor counts, either raw of cps.

save.files

logical If FALSE skip saving of files. Useful to test what files would be modified.

verbose

logical Issue messages when unsupported objects or spectral objects already free of the problematic Java wrapper are encountered.

Value

A character vector with the paths to the updated files, returned silently. As a side effect files can be saved containing updated objects while keeping original files renamed as backups. By default no files are saved.

Details

Spectral data objects acquired directly from a connected spectrometer with 'ooacquire' (< 0.2.5) contain a leftover Java wrapper used to connect to the spectrometer. This is of no use after disconnection, but if it remains in the objects saved to an .rda file loading these files requires 'rJava' and the Java JDK to be available. Some old source_spct and filter_spct objects can also contain the full instrument descriptor including calibration data, which makes the objects unnecessarily large.

This function, searches folders for files with names matching pattern, loads them one by one if modified before the date.limit, removes the spurious Java wrapper and saves the updated objects into a file with the original name after renaming the original file.

The defaults match the defaults of s_irrad_corected() and acq_irrad_interactive() in the current version of 'ooacquire'. Field w containing the jwrapper is deleted from all spectral objects, and for objects containing spectral data expressed in physical units, also fields related to instrument calibration are deleted. If trim.descriptor = FALSE is passed in the call, deleting the w is the action applied to all objects. Any objects in the loaded files that are not spectral objects or collections of spectral objects are kept unchanged.

The date-based file selection uses file modification time as Windows has an unusual logic for file creation time, resulting in creation times being later than modification time when a file is copied. When attached files are downloaded or when files are downloaded they may get the creation and modification times set to the time of downloading. This is only a speed up for avoiding loading of files. Files containing objects that do not need updating will not be modified even if they are loaded.

Warning!

It is strongly recommended that before committing changes a test is first done to check which files will be updated.

See also

ls(), and list.files(), which are used to list objects and files, and rm_jwrapper() used to remove the Java wrapper from the instrument descriptor embedded in objects of class generic_spct and derived classes, respectively.

Use function rm_jwrapper() for individual objects in the R workspace.

Other Functions and methods related to instrument descriptors.: files_s_irrad_update(), instr_defaults(), rm_jwrapper(), update_bad_pixs()