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

NA and NA_integer_ problem #12

Closed
richardvogg opened this issue Apr 23, 2021 · 2 comments
Closed

NA and NA_integer_ problem #12

richardvogg opened this issue Apr 23, 2021 · 2 comments

Comments

@richardvogg
Copy link

First of all, thanks a lot for this package, it is a lot of fun to work with R + music!

When turning a dataframe into a melody I noticed that there is an issue with the NAs.

This is an example which recreates the error:

library(gm)

df <- data.frame(num = 40:50)
df[df == 45] <- NA

m <- Music() + Meter(4, 4) +
Line(pitches = as.list(df$num),
durations = as.list(rep("quarter", nrow(df))))

I get this error message:
Each item of pitches must be a single logical NA, or be a character or numeric vector containing pitch notations and MIDI note numbers.

  • pitches[[6]][1] is NA_integer_.

However, when I run through the list and replace all the NA_integer_ with NA, it works - so it has something to do with the different types of NA_integer_, NA_character_ etc. and the normal NA.

m <- Music() + Meter(4, 4) +
Line(pitches = lapply(as.list(df$num),
function(x) if(is.na(x)) NA else x),
durations = as.list(rep("quarter", nrow(df))))

This probably does not have a high priority, but in case that it is easy to fix, maybe it would be great to interpret NA_integer_ also as pauses.

Thanks again, awesome package!

@flujoo
Copy link
Owner

flujoo commented Apr 23, 2021

@richardvogg I am happy to know you like this package!

The NA issue has already been fixed, you may try the latest version from CRAN or Github. gm now accepts NA of any type.

You can now do something like this:

as.list(c("C4", NA, "D4"))
as.list(c(60, 61, NA, 90))

@richardvogg
Copy link
Author

Thank you for the quick reply, I will install the latest version.

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

No branches or pull requests

2 participants