I’m getting an error when reading in the data and not sure what I’m doing wrong

@Nick_H-K_Seattle_University or anyone else who might know:
I feel silly, but I’m switching over to explore the social distancing dataset and thought I’d use SafeGraphR. However, I’m getting an error when reading in the data and not sure what I’m doing wrong. Thank you for taking a look!

Reading in the first file is triggering this error:
Error in :=(origin_census_block_group, as.character(origin_census_block_group)) :
Check that is.data.table(DT) == TRUE. Otherwise, := and :=(…) are defined for use in j, once only and in particular ways. See help(":=").

Here’s my script:
rm(list = ls())
setwd(“D:/”)

library (SafeGraphR)
library (dplyr)
library (tidyverse)
library (data.table)
library (lubridate)

distancing <- read_distancing(
start = lubridate::ymd(‘2019-01-01’),
end = lubridate::ymd(‘2019-12-31’),
dir = “D:/SocialDistancing/”)

Hmm, I can’t replicate the issue. I’m wondering if maybe it’s failing to find a file to load in. Is your social distancing data structured in the standard from-AWS way of, for example, the January 1 data being in D:/SocialDistancing/2019/01/01/2019-01-01-social-distancing.csv.gz?

Thanks for trying and getting back to me. Yes, that’s how it’s formatted. I downloaded it straight from the SafeGraph AWS via cmd

I wonder if there’s a conflict or a missing library not loaded?

Could you try running this one line at a time and show the results?

r &lt;- lubridate::ymd('2019-01-01')
dir &lt;- "D:/SocialDistancing/"

# Where's the prize
datechar &lt;- as.character(lubridate::as_date(r))
target &lt;- paste0(dir,stringr::str_sub(datechar,1,4),
             '/',stringr::str_sub(datechar,6,7),
            '/',stringr::str_sub(datechar,9,10))
target &lt;- paste0(target,'/',list.files(target))

# Read in only these columns
dt &lt;- data.table::fread(file = target)

class(dt)

is.null(dt$origin_census_block_group)

# Convert CBG to string so we can easily extract state and county indicators
dt[,origin_census_block_group := as.character(origin_census_block_group)]
dt[,c('state_fips','county_fips') := fips_from_cbg(origin_census_block_group)]```

OK, it appears to all run smoothly until the final line.

Here’s the output:
> r <- lubridate::ymd(‘2019-01-01’)
> dir <- “D:/SocialDistancing/”
> # Where’s the prize
> datechar <- as.character(lubridate::as_date(r))
> target <- paste0(dir,stringr::str_sub(datechar,1,4),

  •              '/',stringr::str_sub(datechar,6,7),
    
  •              '/',stringr::str_sub(datechar,9,10))
    

> target ← paste0(target,’/’,list.files(target))
> # Read in only these columns
> dt ← data.table::fread(file = target)
|--------------------------------------------------|
|==================================================|
> class(dt)
[1] “data.table” “data.frame”
> is.null(dt$origin_census_block_group)
[1] FALSE
> # Convert CBG to string so we can easily extract state and county indicators
> dt[,origin_census_block_group := as.character(origin_census_block_group)]
> dt[,c(‘state_fips’,‘county_fips’) := fips_from_cbg(origin_census_block_group)]
Error in fips_from_cbg(origin_census_block_group) :
could not find function “fips_from_cbg”

fips_from_cbg is a SafeGraphR function. Try doing library(SafeGraphR) and running that line again

Yeah, I figured. It’s weird.
> library (SafeGraphR)
> dt[,c(‘state_fips’,‘county_fips’) := fips_from_cbg(origin_census_block_group)]
Error in fips_from_cbg(origin_census_block_group) :
could not find function “fips_from_cbg”

Now that’s odd. Try dt[,c('state_fips','county_fips') := SafeGraphR::fips_from_cbg(origin_census_block_group)] maybe?

Interesting. That throws this error:
Error: ‘fips_from_cbg’ is not an exported object from ‘namespace:SafeGraphR’

Very weird. Try reinstalling SafeGraphR with remotes::install_github("SafeGraphInc/SafeGraphR")

OK! That worked.

Do you think it was just a bad install?

Thank you!

You’re welcome! Might have been a bad install. It’s also updating frequently, maybe fips_from_cbg was left off the namespace acceidentally at some point?