I want to use the Python package peakutils
from within R. To do this, I use the reticulate
package. Here's an example of what I'd like to do.
# Load packages
library(data.table)
library(reticulate)
# Set RNG
set.seed(-1)
# Synthetic data function
foo <- function(x) sin(x) * sqrt(x) + rnorm(length(x), 0, 0.1)
# Create data
dt <- data.table(x = seq(0, 10, by = 0.1))
dt$y <- foo(dt$x)
# Import Python library
pu <- import("peakutils")
# Indices pf peaks
ind <- pu$indexes(dt$y, thres = 0.7)
# Have a look at data
plot(dt)
points(dt[ind], col = "red", pch = 19)
That's great and works as expected. Now, say I want to change the min_dist
parameter, which according to the documentation is an integer. I pass min_dist = 3L
, like so:
# Indices pf peaks now with a larger minimum distance
ind <- pu$indexes(dt$y, thres = 0.7, min_dist = 3L)
and receive the following error:
Error in py_call_impl(callable, dots$args, dots$keywords) :
TypeError: only integer arrays with one element can be converted to an index
It is expecting an array with a single element that is an integer, but – as far as I can see – this is exactly what I'm passing so why am I receiving this error?