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

Error: Variable in 'formula' must be numeric. #75

Closed
daveglover opened this issue May 20, 2021 · 5 comments
Closed

Error: Variable in 'formula' must be numeric. #75

daveglover opened this issue May 20, 2021 · 5 comments

Comments

@daveglover
Copy link

I'm having an issue with certain functions that require a "formula" such as psdCalc and psdPlot. Length is not being recognized as numeric. I simplified my data frame to just one species and associated lengths (nearest mm) to demonstrate the issue. I'm able to run the simulated yellow perch data from examples in the help files just fine. Love the FSA package and book, btw.

df <- rawdata[c("Species","Length")]
psd <- psdCalc(~Length, data=df, species="Black Crappie", units="mm", digits=1)
Error: Variable in 'formula' must be numeric.
str(df)
tibble [244 x 2] (S3: tbl_df/tbl/data.frame)
$ Species: chr [1:244] "Black Crappie" "Black Crappie" "Black Crappie" "Black Crappie" ...
$ Length : num [1:244] 178 308 213 223 226 117 209 227 276 266 ...
is.numeric(df$Length)
[1] TRUE

Thanks in advance for any help!
Dave

@droglenc
Copy link
Contributor

Dave,

Thanks for the note.

Is there any possibility that your "Length" variable is actually "Length " (with the extra space on the end). Your results from str() imply that that might be the case (there is a space between "Length" and the colon but not between "Species" and the colon).

If not, I don't see the issue immediately. Is it possible for you to send me your data file so that I can try repeating the issue and then troubleshooting from there. You can send it directly to derek@derekogle.com.

Thanks.

@daveglover
Copy link
Author

That didn't seem to be the issue. I did find, however, that if I explicitly define df as a data frame I have no issues. I assumed I was working with a data frame, but it turns out when I import my data from a CSV file the data is coming in as class = tbl_df.

df <- data.frame(rawdata[c("Species", "Length")])

@droglenc
Copy link
Contributor

That was my second guess as I have had problems with other functions relative to the data being a tibble (the tbl_df). I will get that fixed for the next version. I will let you know when it is fixed in the development version so you can give that a try if you would like as it may be a while before we release the next version to CRAN.

Thanks for letting me know and thanks for your patience.

@daveglover
Copy link
Author

Easy enough to be more explicit in my programming. Thank you!

@droglenc
Copy link
Contributor

More and more people are using methods to read data that result in tbl_df, so we need to fix this. Re-opening so I remember to fix this.

@droglenc droglenc reopened this May 20, 2021
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