Error code in my RStudio but not when ran on someone else's RStudio

I'm very new when it comes to RStudio and I was given a code that I modified and used to create vertical distribution plots and it worked perfectly. I needed to add a "N=" on each plot and when I went back to use this code and same data, I am now receiving a

"Error in -0.01 * height : non-numeric argument to binary operator"

I never received this error before and I sent the code and data to my friend for them to try out and they are not receiving this error message.

What could be causing this and why would this error be showing up now and not before?

I tried the code the way it was ran before adding anything new to it.

Please help!
This is the code

pteropod=R_standard_data_updated

filepath <- "Pteropod Distribution Folder"
#This is the drive and folder where you want it to store your plots

len <- (length(pteropod[0,])-1)/2
position <- 1
for (i in 1:len){
  path <- paste(names(pteropod[i+position]),".jpeg")
  jpeg(path)
  #This tells it to save your plots as jpegs and store them in the filepath you created above
  #these are the 2 lines that set the max each loop
  daymax=round(1.2*max(pteropod[i+position]),digits=2)
  
  nightmax=round(1.2*max(pteropod[i+1+position]),digits=2)
  
  maxi=max(c(daymax,nightmax))
  
  barplot(matrix(-pteropod[,i+position]),beside= TRUE,horiz=TRUE,col="white",axes=F,xlim=c(-maxi,maxi),width=c(300,200,400,400,200))
  barplot(matrix(pteropod[,i+1+position]), beside= TRUE, horiz=TRUE,col="black",add=TRUE,axes=F,xlim=c(-maxi,maxi),width=c(300,200,400,400,200))
  box()
  axseq <- seq(-maxi,maxi,maxi/5)
  axis(3,at=axseq,labels=abs(axseq),cex.axis=1)
  
  mtext(side=3,expression(paste(Abundance," (No. ",10^-7,m^-3,")")),2,cex=1.5)
  
  mtext(side=2,"Depth (m)",cex=1.5,2.5)
  
  axis(2,at=c(300,600,800,1200,1600,1800),labels=c(1500,1200,1000,600,200,0),cex.axis=1)
  
  mtext(side=1,"Day",-3,adj=0.20,cex=2)
  
  mtext(side=1,"Night",-3,adj=0.85,cex=2)
  
  mtext(side=1, str_replace(names(pteropod[i+position]), "\\.", " "),1,cex=2,font=3)
  
  title(main=bquote(atop(italic(.(i)), "N = " ~.(nrow(current.sp)))))
  
  position <- position + 1
  
  dev.off()
  
}

Thank you in advance for any help!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.