Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Add support for vectors in addition to Open Specy objects #166

Open
1 task done
wincowgerDEV opened this issue Feb 2, 2024 · 2 comments
Open
1 task done
Labels
enhancement New feature or request

Comments

@wincowgerDEV
Copy link
Owner

Guidelines

  • I agree to follow this project's Contributing Guidelines.

Description

I know we had this chat a while back but I was thinking it could be good to revisit it. I am running into some challenges implementing the Open Specy package because sometimes it is easiest to just implement the functions on the spectra vectors individually. At the core, I think many of the functions already operate on vectors, and we are currently hiding that capability from the user.

Problem

Sometimes it is easiest to run function on intensity vectors rather than Open Specy objects.

Proposed Solution

Can be implemented as default function in s3 for most of the spectral intensity functions. Could also be implemented as .Vector functions in S3.

Alternatives Considered

Disallow vector operations for function consistency, require users to create their own routines.

@wincowgerDEV wincowgerDEV added the enhancement New feature or request label Feb 2, 2024
@wincowgerDEV
Copy link
Owner Author

I think this would also make it easier to combine functions with eachother.

@wincowgerDEV
Copy link
Owner Author

Another useful thing to add to this update would be too allow ignoring NA values in spectral intensities. I got this function for it:

# Define the function to apply, ignoring NA values
apply_function_ignoring_na <- function(x, fun) {
  # Identify NA positions
  na_positions <- is.na(x)
  
  # Apply the function only to non-NA elements
  result <- numeric(length(x))
  result[!na_positions] <- fun(x[!na_positions])
  
  # Reinsert NA values in their original positions
  result[na_positions] <- NA
  
  return(result)
}

# Example vector with NA values
example_vector <- c(1, NA, 3, NA, 5)

# Example function to apply (e.g., multiply by 2)
example_function <- function(x) {
  x * 2
}

# Apply the function to the vector, ignoring NA values
result_vector <- apply_function_ignoring_na(example_vector, example_function)

# Print the result
print(result_vector)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant