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 in format_data(x, ...) : object 'xx' not found #72

Open
ingomiller opened this issue Jan 10, 2025 · 2 comments
Open

Error in format_data(x, ...) : object 'xx' not found #72

ingomiller opened this issue Jan 10, 2025 · 2 comments

Comments

@ingomiller
Copy link

Hi,

I keep getting this error "Error in format_data(x, ...) : object 'xx' not found" when using (format_data) for (fit_ssm) although it has worked perfectly fine using the exact same dataset before.

Code below and subset data attached:

str(df)
spc_tbl_ [50 × 10] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
$ id : num [1:50] 172899 172899 172899 172899 172899 ...
$ date: POSIXct[1:50], format: "2018-10-26 06:27:00" "2018-10-26 07:07:30" "2018-10-26 08:11:37" ...
$ lc : chr [1:50] "3" "3" "A" "A" ...
$ lon : num [1:50] 146 146 146 146 146 ...
$ lat : num [1:50] -14.2 -14.2 -14.2 -14.2 -13.9 ...
$ smaj: num [1:50] 511 336 5571 714 17066 ...
$ smin: num [1:50] 65 184 212 134 5362 ...
$ eor : num [1:50] 83 167 158 148 100 101 94 38 39 59 ...
$ x.sd: logi [1:50] NA NA NA NA NA NA ...
$ y.sd: logi [1:50] NA NA NA NA NA NA ...

df <- aniMotum::format_data(df,
id = "id",
date = "date",
lc = "lc",
coord = c("lon", "lat"),
epar = c("smaj", "smin", "eor"),
sderr = c("x.sd", "y.sd"),
tz = "UTC")

fit <- df |>
aniMotum::fit_ssm(vmax = 1.15,
model = "crw",
time.step = 24,
spdf = TRUE,
#map = list(psi = factor(NA)),
control = ssm_control(verbose = 1, se = TRUE),
pf=FALSE)

Error in format_data(x, ...) : object 'xx' not found

I have even re-installed R, RStudio and Rtools, updated all packages, and tried 4 different computers (Macs and PCs).
I'm running out of ideas and hope @ianjonsen or anyone else who has experienced this issue can help?

Cheers
Ingo

GitHub_aniMotum_example_subset.csv

@ianjonsen
Copy link
Owner

So your case is one I didn't anticipate. Your data.frame df already has all the variables that format_data would add. This should usually not occur with unformatted Argos track data as the variables x.sd and y.sd are aniMotum constructions. If you do the following, your example runs without error:

## drop the `x.sd` and `y.sd` variables
df <- df[, 1:8]

fit <- df |>
aniMotum::fit_ssm(vmax = 1.15,
model = "crw",
time.step = 24,
spdf = TRUE,
#map = list(psi = factor(NA)),
control = ssm_control(verbose = 1, se = TRUE),
pf=FALSE)

Note, in your case there is no need to use format_data because the variables in df already conform exactly to those expected by fit_ssm.

I've made a small fix to format_data so your originally structured data will not result in an error.

@ingomiller
Copy link
Author

Hi Ian,

Thanks for this, it worked!

Cheers

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