Skip to content

Commit

Permalink
Merge branch 'develop' into update-gha-workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
GegznaV committed May 1, 2024
2 parents 1726e26 + 0e3e4c0 commit 679838a
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 187 deletions.
20 changes: 11 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ By contributing, you understand and agree that your work becomes the part of the

* Use package [styler](http://styler.r-lib.org/) with RStudio add-in to easily re-style your code to comply with the guidelines.
* When appropriate, prefer this naming scheme for the internal functions – `.<generic>_<x><y><...>` with `<x>`, `<y>`, etc. the first, second and later parameter/operand:
- _ ... missing
- a ... array
- d ... data frame
- f ... formula
- h ... hyperSpec object
- m ... matrix
- n ... numeric (scalar, vector, or matrix)
- _ ... missing
- a ... array
- d ... data frame
- f ... formula
- h ... hyperSpec object
- m ... matrix
- n ... numeric (scalar, vector, or matrix)

* Each new function should be accompanied with appropriate unit tests.
* If a unit test needs to be disabled temporarily, please use `skip("reason for switching off")`.
Expand Down Expand Up @@ -130,22 +130,24 @@ Every commit should be related to one feature only, but the commit should group

The project adheres to the semantic versioning guidelines, as outlined at https://semver.org/ (Work in progress, see [#123](https://github.com/cbeleites/hyperSpec/issues/123)).

Briefly, the version string has the form `x.y.z` (or `major.minor.patch`), where the major number gets incremeted if a release introduces breaking changes, the minor one after any changes in functionality (new features of bugfixes), and the patch number is increased after any trivial change. If a major or minor number is incremented, all subsequent ones are set to zero.
Briefly, the version string has the form `x.y.z` (or `major.minor.patch`), where the major number gets incremented if a release introduces breaking changes, the minor one after any changes in functionality (new features of bugfixes), and the patch number is increased after any trivial change. If a major or minor number is incremented, all subsequent ones are set to zero.

The version numbers refer only to commits in the `master` branch, and get incremented in one of two cases:

* during the release preparation, when a `release/x.y.z` branch buds off `develop` and merges into `master`.
* after a hotfix, which also results in a new commit on `master`.
* development branches have version `x.x.x.9000` (or `.9001` and so on - but that is rarely needed).
This is important since **pkgdown** uses the `.9000` to distinguish between documentation for the released version vs. the development version.

### Release Process

The process starts when the package is in a stable state that can be released to CRAN (release candidate). First, decide on a new version number `x.y.z` based on the severity of changes. Then:

* Create a `release/x.y.z` branch using `git flow release start <x.y.z>` and push it with `git flow publish`
* Open a pull request that merges into `master`
* Update the version number in the `DESCRIPTION` file
* Verify that the changes are listed in `NEWS.md`
* Confirm that the package can be built for each plaftorm
* Confirm that the package can be built for each platform
* Ensure that all check are passed on the tarballs you build (either on your machine or using CI) with `R CMD check --as-cran <package.tar.gz>`. The checks must pass for `R` versions `R-oldrel`, `R-release`, `R-patched`, and `R-devel`.
* If any bugs are found, they must be fixed in the very same branch (see [here](https://stackoverflow.com/a/57507373/6029703) for details)
* Once everything works use `git flow release finish <x.y.z>`. It will merge the release branch into both `master` and `develop`, and will assign a tag to the newly created commit in the `master` branch.
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Description: Comfortable ways to work with hyperspectral data sets,
of information associated with each of the spectra. The spectra can be data
as obtained in XRF, UV/VIS, Fluorescence, AES, NIR, IR, Raman, NMR, MS,
etc. More generally, any data that is recorded over a discretized variable,
e.g. absorbance = f (wavelength), stored as a vector of absorbance values
e.g. absorbance = f(wavelength), stored as a vector of absorbance values
for discrete wavelengths is suitable.
License: GPL (>= 3) + file LICENSE
LazyLoad: yes
Expand Down
55 changes: 28 additions & 27 deletions R/initialize.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

#' Create a `hyperSpec` object
#' Create a `hyperSpec` Object
#'
#' To create a new `hyperSpec` object, the following functions can be used:
#' To create a new `hyperSpec` object, you can use one of the following functions:
#' - [new()] (i.e., `new("hyperSpec", ...)`);
#' - `new_hyperSpec()`.
#'
#' @note
#'
#' A `hyperSpec` object is an S4 object, so its initialization is carried out
#' by calling `new("hyperSpec", ...)`. Function `new_hyperSpec()` is just
#' a convenience function.
#' A `hyperSpec` object is an S4 object, so its initialization is performed
#' by calling `new("hyperSpec", ...)`. The function `new_hyperSpec()` is provided
#' for convenience.
#'
#' @docType methods
#'
Expand All @@ -29,30 +28,30 @@
#' A spectra matrix with spectra in rows and wavelength intensities in
#' columns.
#'
#' The `spc` does not need to be an R `matrix`, but must be an object
#' The `spc` does not need to be an R `matrix`, but it must be an object
#' convertible to a matrix via `I(as.matrix(spc))`.
#'
#' @param data (`data.frame`) \cr
#' A `data.frame` with extra (non-spectroscopic) data in columns.
#' The data frame may also contain a special column `spc` with a `matrix`
#' of spectroscopic data.
#' (Such single column that contains matrix can be created with
#' (Such a single column that contains a matrix can be created with
#' `data.frame(spc = I(as.matrix(spc)))`.
#' However, it will usually be more convenient if the spectra are given
#' via argument `spc`.)
#' However, it is usually more convenient to provide the spectra
#' via the `spc` argument.)
#'
#' @param wavelength (numeric vector) \cr
#' The wavelengths corresponding to the columns of `spc`.
#'
#' If no wavelengths are given, an appropriate vector is derived from the
#' column the column names of `data$spc`. If this is not possible,
#' column names of `data$spc`. If this is not possible,
#' `1:ncol(data$spc)` is used instead.
#'
#' @param labels A named `list`:
#' - list's element names should containing one or more names of `data`
#' columns as well as special name `.wavelength` for `wavelength`s ).
#' - list's element names should contain one or more names of `data`
#' columns as well as the special name `.wavelength` for `wavelength`s.
#' - list's element values should contain the labels for the indicated
#' names usually either in a for of character strings or
#' names, usually in the form of character strings or
#' [plotmath][grDevices::plotmath()] expressions.
#' (The labels should be given in a form ready
#' for the text-drawing functions, see [grDevices::plotmath()]).
Expand All @@ -61,24 +60,26 @@
#' columns of `data` and `wavelength` is used.
#'
#' @param gc (logical) \cr Use garbage collection.
#' If option `gc` is `TRUE`, the initialization will have frequent calls
#' to [base::gc()], which can help to avoid swapping or running out of
#' memory. The default value of `gc` can be set via [hy_set_options()].
#' If the option `gc` is set to `TRUE`, the initialization will have
#' frequent calls to [base::gc()], which can help avoid swapping or
#' running out of memory.
#' The default value of `gc` can be set via [hy_set_options()].
#'
#' @param log This parameter is currently **ignored**. It is present due to
#' backwards compatibility.
#' backward compatibility.
#'
#' @param .Object A new `hyperSpec` object.
#'
#'
#' @author C.Beleites, V. Gegzna
#' @author C. Beleites, V. Gegzna
#' @seealso
#'
#' - [methods::new()] for more information on creating and initializing S4 objects.
#' - [grDevices::plotmath()] on expressions for math annotations as for slot `label`.
#' - [hy_set_options()] setting `hyperSpec` options.
#' - [grDevices::plotmath()] for expressions used for math annotations as in the `label` slot.
#' - [hy_set_options()] for setting `hyperSpec` options.
#'
#' @keywords methods datagen
#'
#' @concept hyperSpec conversion
#'
#' @examples
Expand All @@ -98,7 +99,7 @@
#' colnames(spc) <- 600:603
#' new("hyperSpec", spc = spc) # wavelength taken from colnames (spc)
#'
#' # given wavelengths precede over colnames of spc
#' # given wavelengths take precedence over colnames of spc
#' new("hyperSpec", spc = spc, wavelength = 700:703)
#'
#' # specifying labels
Expand All @@ -123,7 +124,7 @@ NULL
.initialize <- function(.Object, spc = NULL, data = NULL, wavelength = NULL,
labels = NULL, gc = hy_get_option("gc"),
log = "ignored") {
# Do the small stuff first, so we need not be too careful about copies
# Handle the small stuff first, so we don't need to be too careful about copies

# The wavelength axis
if (!is.null(wavelength) && !is.numeric(wavelength)) {
Expand Down Expand Up @@ -197,7 +198,7 @@ NULL
if (gc) base::gc()

if (!is.null(data$spc) && !(is.null(spc))) {
warning("Spectra in data are overwritten by argument spc.")
warning("Spectra in data are overwritten by the argument spc.")
}

# Deal with spectra
Expand All @@ -216,7 +217,7 @@ NULL
dim <- dim(spc)
spc <- suppressWarnings(as.numeric(spc))
if (all(is.na(spc))) {
stop("spectra matrix needs to be numeric or convertable to numeric")
stop("spectra matrix needs to be numeric or convertible to numeric")
} else {
warning("spectra matrix is converted from ", class(data$spc), " to numeric.")
}
Expand All @@ -227,7 +228,7 @@ NULL
if (gc) base::gc()

if (!is.null(spc)) {
attr(spc, "class") <- "AsIs" # I seems to make more than one copy
attr(spc, "class") <- "AsIs" # It seems to make more than one copy
if (gc) base::gc()
}

Expand All @@ -254,7 +255,7 @@ NULL

.Object <- .spc_fix_colnames(.Object) # For consistency with .wl<-

# Finally: check whether we got a valid hyperSpec object
# Finally, check whether we got a valid hyperSpec object
validObject(.Object)

.Object
Expand Down
42 changes: 21 additions & 21 deletions R/write_txt_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
#' @rdname write_txt
#' @aliases write_txt_long
#'
#' @param file Filename or connection.
#' @param object `hyperSpec` object.
#' @param cols Column names specifying the column order.
#' @param order Which columns should be [base::order()]ed? Parameter `order` is
#' used as index vector into a `data.frame` with columns given by `cols`.
#' @param na.last Handed to [base::order()] by `write_txt_long`.
#' @param quote,sep,col.names,row.names Have their usual meaning
#' (see [utils::write.table()]), but different default values.
#'
#' For file import, `row.names` should usually be `NULL` so that the first
#' column becomes a extra data column (as opposed to row names of the
#' extra data).
#' @param col.labels Should the column labels be used rather than the
#' colnames?
#' @param file Filename or connection to write the data.
#' @param object A `hyperSpec` object to export.
#' @param cols Column names specifying the order of columns in the output file.
#' @param order Which columns should be sorted using [base::order()]? The `order`
#' parameter is used as an index vector into a `data.frame` with columns
#' specified by `cols`.
#' @param na.last Passed to [base::order()] by `write_txt_long`.
#' @param quote,sep,col.names,row.names These parameters have their usual meaning
#' as used in [utils::write.table()], but with different default values.
#'
#' For file import, `row.names` should usually be set to `NULL` so that the first
#' column becomes an extra data column (instead of row names of the extra data).
#'
#' @param col.labels Should the column labels be used rather than the colnames?
#' @param append Should the output be appended to an existing file?
#' @param decreasing logical vector giving the sort order.
#' @param header.lines Toggle one or two line header (wavelengths in the
#' @param decreasing A logical vector specifying the sort order for columns.
#' @param header.lines Toggle one or two-line headers (wavelengths in the
#' second header line) for `write_txt_wide`.
#' @param ... arguments handed to [utils::write.table()].
#' @param ... Additional arguments passed to [utils::write.table()].
#'
#'
#' @concept io
Expand All @@ -39,13 +39,13 @@
#'
#' ## Export & import Matlab files
#' if (require(R.matlab)) {
#' # export to matlab file
#' # Export to a Matlab file
#' writeMat(paste0(tempdir(), "/test.mat"),
#' x = flu[[]], wavelength = flu@wavelength,
#' label = lapply(flu@label, as.character)
#' )
#'
#' # reading a matlab file
#' # Read a Matlab file
#' data <- readMat(paste0(tempdir(), "/test.mat"))
#' print(data)
#' mat <- new("hyperSpec",
Expand Down Expand Up @@ -86,12 +86,12 @@
#'
#' read.txt.wide(
#' file = paste0(tempdir(), "/flu.txt"),
#' # give columns in same order as they are in the file
#' # Give columns in the same order as they are in the file
#' cols = list(
#' spc = "I / a.u",
#' c = expression("/"("c", "mg/l")),
#' filename = "filename",
#' # plus wavelength label last
#' # Plus wavelength label last
#' .wavelength = "lambda / nm"
#' ),
#' header = TRUE
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
[![CRAN status](https://www.r-pkg.org/badges/version-last-release/hyperSpec)](https://cran.r-project.org/package=hyperSpec)
[![metacran downloads](https://cranlogs.r-pkg.org/badges/grand-total/hyperSpec)](https://cran.r-project.org/package=hyperSpec)
[![metacran downloads](https://cranlogs.r-pkg.org/badges/hyperSpec)](https://cran.r-project.org/package=hyperSpec)
[![R-CMD-check](https://github.com/r-hyperspec/hyperSpec/workflows/R-CMD-check/badge.svg?branch=develop)](https://github.com/r-hyperspec/hyperSpec/actions)
[![R-CMD-check](https://github.com/r-hyperspec/hyperSpec/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-hyperspec/hyperSpec/actions/workflows/R-CMD-check.yaml)
[![Codecov](https://codecov.io/gh/r-hyperspec/hyperSpec/branch/develop/graph/badge.svg)](https://codecov.io/gh/r-hyperspec/hyperSpec?branch=develop)
![Website (pkgdown)](https://github.com/r-hyperspec/hyperSpec/workflows/Website%20(pkgdown)/badge.svg)
[![Website (pkgdown)](https://github.com/r-hyperspec/hyperSpec/actions/workflows/pkgdown.yaml/badge.svg)](https://github.com/r-hyperspec/hyperSpec/actions/workflows/pkgdown.yaml)
<!-- [![license](https://img.shields.io/badge/license-GPL--3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html) -->
<!-- badges: end -->

Expand All @@ -21,7 +21,7 @@
<font color="red" size=4>
<b>Package `hyperSpec` is under overhaul now.</b>
So this website is still under construction and the contents as well as resources are not fully updated yet.
The documentation of version `0.100.0` is not present here too.
The documentation of version <code>0.100.2</code> is not present here either.
</font>
</center>
<br>
Expand All @@ -30,7 +30,7 @@ The documentation of version `0.100.0` is not present here too.

[**R**](https://www.r-project.org/) package **hyperSpec** is the main package in the [**`r-hyperspec`**](https://r-hyperspec.github.io/) family of packages.
The goal of **hyperSpec** (and whole **`r-hyperspec`**) is to make the work with hyperspectral data sets, (i.e. spatially or time-resolved spectra, or spectra with any other kind of information associated with each of the spectra) more comfortable.
The spectra can be data as obtained during
The spectra can be data obtained during
[XRF](https://en.wikipedia.org/wiki/X-ray_fluorescence),
[UV/VIS](https://en.wikipedia.org/wiki/Ultraviolet%E2%80%93visible_spectroscopy),
[Fluorescence](https://en.wikipedia.org/wiki/Fluorescence_spectroscopy),
Expand Down Expand Up @@ -59,7 +59,7 @@ The documentation of the other **`r-hyperspec`** family packages can be found at

## Issues, Bug Reports and Feature Requests

Issues, bug reports and feature requests should go [here](https://github.com/r-hyperspec/hyperSpec/issues)!
Issues, bug reports, and feature requests should go [here](https://github.com/r-hyperspec/hyperSpec/issues)!
<!-- ---------------------------------------------------------------------- -->


Expand Down Expand Up @@ -96,7 +96,7 @@ remotes::install_github("r-hyperspec/hyperSpec")
```

**NOTE 1:**
Usually, "Windows" users need to download, install and properly configure **Rtools** (see [these instructions](https://cran.r-project.org/bin/windows/Rtools/)) to make the code above work.
Usually, "Windows" users need to download, install, and properly configure **Rtools** (see [these instructions](https://cran.r-project.org/bin/windows/Rtools/)) to make the code above work.

**NOTE 2:**
This method will **not** install package's documentation (help pages and vignettes) into your computer.
Expand All @@ -115,14 +115,14 @@ So you can either use the [online documentation](https://r-hyperspec.github.io/)
1. From the **hyperSpec**'s GitHub [repository](https://github.com/r-hyperspec/hyperSpec):
- If you use Git, `git clone` the branch of interest.
You may need to fork it before cloning.
- Or just chose the branch of interest (1 in Figure below), download a ZIP archive with the code (2, 3) and unzip it on your computer.
- Or just choose the branch of interest (1 in Figure below), download a ZIP archive with the code (2, 3), and unzip it on your computer.
![image](https://user-images.githubusercontent.com/12725868/89338263-ffa1dd00-d6a4-11ea-94c2-fa36ee026691.png)

2. Open the downloaded directory in RStudio (preferably, as an RStudio project).
- The code below works correctly only if your current working directory coincides with the root of the repository, i.e., if it is in the directory that contains file `README.md`.
- If you open RStudio project correctly (e.g., by clicking `project.Rproj` icon ![image](https://user-images.githubusercontent.com/12725868/89340903-26621280-d6a9-11ea-8299-0ec5e9cf7e3e.png) in the directory), then the working directory is set correctly by default.

3. In RStudio 'Console' window, run the code (provided below) to:
3. In the RStudio 'Console' window, run the code (provided below) to:
a. Install packages **remotes** and **devtools**.
b. Install **hyperSpec**'s dependencies.
c. Create **hyperSpec**'s documentation.
Expand All @@ -146,7 +146,7 @@ devtools::install(build_vignettes = TRUE)
```

**NOTE 1:**
Usually, "Windows" users need to download, install and properly configure **Rtools** (see [these instructions](https://cran.r-project.org/bin/windows/Rtools/)) to make the code above work.
Usually, "Windows" users need to download, install, and properly configure **Rtools** (see [these instructions](https://cran.r-project.org/bin/windows/Rtools/)) to make the code above work.

</details>

Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ reference:
- contents:
- has_concept("labels")


- title: '8. Other functions' # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
desc: "Functions not mentioned above."
- contents:
Expand Down
Loading

0 comments on commit 679838a

Please sign in to comment.