Error in mutate ( ): problem while computing

I'm having a hard time debugging a script that was given to me. Essentially it's supposed to grab data from postgres and make a power-point off it. Halfway through the script I get an error in mutate, across, and usemethod. I narrowed down where exactly the problem is in the code luckily through browser, but I'm not sure how I should tackle solving the issue. Not asking for a solve but just a nudge in the right direction as to what I could be doing. I'm thinking maybe the source updated title columns which might affect the names that are trying to be called. Here's a code snippet:

  total_stats = stats_combined %>% 
    rename(`Net Absorption` = `Net Absorption QTD - Total`, 
           `Net Absorption YTD` = `Net Absorption YTD - Total`,
           `Construction Deliveries` = `Construction Deliveries QTD`) %>% 
    filter(Submarket %in% submarket_order) %>% 
    mutate(Submarket = factor(Submarket, levels = submarket_order, ordered = T)) %>% 
    arrange(Submarket) %>% 
    # glimpse()
    mutate(across(c(`Direct Vacancy Rate`, `Overall Vacancy Rate`, `Overall Availability Rate`), scales::percent, accuracy = .1),
           across(any_of(sum_vars), 
                  scales::dollar, ,accuracy = 1, style_negative="parens", prefix=""),
           across(any_of(c("Full Service Gross Asking Rate", "Lease Rate")),
                  scales::dollar)) %>%
    select(Submarket, all_of(stat_order))
  
  market_stats_table(total_stats, 
                     cell_width = if_else(property_type == "Office", 1.05, .9), 
                     cell_height = if_else(property_type == "Office", .33, .27),
                     submarket_order,
                     totals)
}

Here's the actual error message:

<error/dplyr:::mutate_error>
Error in `mutate()`:
! Problem while computing `..2 = across(...)`.
Caused by error in `across()`:
! Problem while computing column `Property Count`.
Caused by error in `UseMethod()`:
! no applicable method for 'round_any' applied to an object of class "integer64"
---

As a workaround, try running

stats_combined$`Property Count` <- as.integer(stats_combined$`Property Count`)

before that piece of code.
A better fix would be to figure out why the Property Count column has the class interger64. You can use str(stats_combined) to see what class the column has. Track down when the column gets that class.

You could try adding library(bit64) before your code.

Large 64bit integers can result in odd behaviours without that package I've found.

I tried running str(stats_combined) but stats_combined doesn't seem to be recognized as an object. I'm wondering if that might be the issue. Essentially I have a source script with all the functions and another script that calls on it to make the power point. One of the many errors I get when debugging from source is this.

Error in `across()`:
! Must be used inside dplyr verbs.

I looked into it and it seems like I should only get this when loading plyr with dplyr because they have some functions that have the same names, but I'm using neither. I'm loading dbplyr, I'm thinking maybe this might be something else I can look at and check the other packages. If load order is something I can check do you have any idea how I would go about that? Let me know if I'm being confusing or not clear, I know it can be hard bouncing ideas when you don't readily have the whole script in front of you.

Thanks! I tried it but it didn't seem to do much. I still get the error .

If stats_combined did not exist when it is needed, you would get an "object not found" error at the lines of code that use that object. If you are not seeing that, then you probably ran str() before stats_combined had been assigned. I cannot tell without having all of your code and the data required to run it.
If you are concerned about a function from one package masking a function with the same name from another package, you can designate the package. For example, instead of running across(), you can use dplyr::across(). That gets tedious but it can be useful in the right place.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.