Home / Forum
Please or Register to create posts and topics.

Error with import.meas function

I have been using the fishresp package for some time now, and I have now received an error code during the import.meas function.

For background, this data was collected in Auto Resp. And I have already converted my background files (both before and after) along with converting the RMR measurement file from percent_a.s. to mg_per_l using the convert.respirometry function. This worked seamlessly and provided a new a file, which I have then used in following function.

I then imported the info about the chamber volume and animal mass using the function.

The background files were imported via the import.test function, and this provided no errors.

But I then try to import the RMR file via import.meas and receive this error code.

Error in `$<`(`*tmp*`, "Time", value = c(1L, 2L, 3L, 4L, 5L, : replacement has 23040 rows, data has 22974

Any help would be appreciated. I have uploaded my RMR raw file and the converted file.

Uploaded files:
  • You need to login to have access to uploads.

Dear Sir/Madam,

Thank you a lot for informing us about this issue and attaching sample files.
I will work on it in the beginning of the next week and let you know about the results here.

Have a nice weekend,

jlonthair has reacted to this post.

Thanks Sergey,

Have a great weekend!


Sergey Morozov has reacted to this post.
Sergey Morozov

Hello Joshua,

Based on the source code of the 'import.meas' function, FishResp expects to have a similar length of all measurement phases (i.e. 120 raws in your case per measurement phase). When some measurement phases (M5 in your case) are different in length than M1, this error will pop up.

The quick fix for you is to find and remove all raws with a mismatched length of measurement phases (in your file only raws with 'M5'). Then, raw data will be imported without problems.

HOWEVER, such sensitivity to raw data might be considered as a bug, thus I need to double check that there is no side affect on other parts of the FishResp pipeline if I get rid of length crosschecking. I will be able to work on it and submit a new version of the R package to CRAN only next week.

BUT, you are free to modify this function inside the R package and share the result if you find a suitable solution here or on GitHub webpage.

Potential source code that should be changed to avoid length mismatch error in the function 'import.meas'

  # here is a quick lesson in how to create an ordered factor
  # note the odering of levels for the factor 'Phase' in the current dataframe

  # now creating the re-ordered factor
  z <-$Phase
  z <- gsub("[M]","",z)
  z <- as.numeric(z)
  x <- ordered($Phase, levels=paste(rep("M",length(levels($Phase))), head(z, n=1):tail(z, n=1), sep=""))$Phase<-x
  # note the new class of 'Phase' and the new ordering

Hope, either a quick fix or the next R package update will work for you. Do not hesitate to ask further questions!

Best wishes,