【发布时间】:2021-12-13 06:58:38
【问题描述】:
我一直在尝试使用以下网址运行以下代码:https://files.hawaii.gov/dbedt/economic/data_reports/DLIR/LFR_LAUS_LF.xls。
该网址下载一个 xls 文件。但是在 R 中使用 read_xls(temp, sheet = 1) 命令给了我一个 R。有什么解决方案吗?该文件应该存储在临时文件夹中。
从 DBEDT 抓取就业数据
rm(list = ls(all = TRUE))
#loads necessary packages to run codes
library(dplyr)
library(tidyverse)
library(readxl)
library(stringr)
library(taRifx)
library(lubridate)
#set url link for xls
# url <- "https://www.hirenethawaii.com/admin/gsipub/htmlarea/uploads/LFR_LAUS_LF.xls"
url <- "https://files.hawaii.gov/dbedt/economic/data_reports/DLIR/LFR_LAUS_LF.xls"
#create a temp file to load the xls and download the xls
temp <- tempfile(fileext = "xls")
download.file(url = url, destfile = temp)
#create a function to select only the columns we want
#grab date (col 2), labor force (col 3), employed persons (col 4), and unemployment rate (col 6) columns from state data
keep_cols <- function(data) {
data <- data %>%
select(2,3,4,6) %>%
rename(date = 1, lf = 2, empl = 3, ur = 4)
return(data)
}
#importing the xls sheets into our r environment
state_xls <- read_xls(temp, sheet = 1) %>% keep_cols() %>% mutate(geo = "HI")
错误如下:
Error:
filepath: C:\Users\Jon Doe\AppData\Local\Temp\Rtmp0iFXmt\file8eb8142165d0xls
libxls error: Unable to open file
我使用的是 Windows 笔记本电脑,代码最初是用 Macbookbbb 编写的
【问题讨论】:
-
奇怪,这对我有用,没有任何错误。
-
@RonakShah 我正在使用 PC 顺便说一句。任何其他可以帮助它工作的修改?