options( survey.lonely.psu = "adjust" )
library(survey)
library(lodown)
# retrieve a listing of all available extracts for the youth risk behavioral
# surveillance system
yrbss_cat <- get_catalog( "yrbss" , output_dir = file.path( path.expand( "~" ) , "YRBSS" ) )
# limit the catalog to only years 2005-2015
yrbss_cat <- subset( yrbss_cat , year %in% seq( 2005 , 2015 , 2 ) )
# download the yrbss microdata
lodown( "yrbss" , yrbss_cat )
该代码应下载yrbss数据集并转换为rda文件,但不起作用。有人可以帮忙吗?
错误如下
选项(survey.lonely.psu =“ adjust”) 库(调查)正在加载所需的软件包:网格正在加载所需的软件包:矩阵正在加载所需的软件包:生存
附加软件包:“调查”
以下对象被“ package:graphics”屏蔽:
dotchart
警告消息:“ survey”软件包是在R版本3.4.4下构建的
库(关闭)
获取有关青少年风险行为的所有可用摘录的列表
监视系统
yrbss_cat <-get_catalog(“ yrbss”,output_dir = file.path(path.expand(“〜”),“ YRBSS”))yrbss的建筑目录
获取有关青少年风险行为的所有可用摘录的列表
监视系统
yrbss_cat <-get_catalog(“ yrbss”,output_dir = file.path(path.expand(“ U:/”),“ YRBSS”)))yrbss的建筑目录
yrbss_cat目录年dat_url 1 1991 1991
https://ftp.cdc.gov/pub/data/yrbs/1991/yrbs1991.dat 2 1993 1993 https://ftp.cdc.gov/pub/data/yrbs/1993/yrbs1993.dat 3 1995 1995 https://ftp.cdc.gov/pub/data/yrbs/1995/nchrbs1995.dat 1995年4月 1995
https://ftp.cdc.gov/pub/data/yrbs/1995/yrbs1995.dat 5 1997 1997 https://ftp.cdc.gov/pub/data/yrbs/1997/yrbs1997.dat 6 1998 1998 https://ftp.cdc.gov/pub/data/yrbs/1998/ayrbs1998.dat 7 1999 1999 https://ftp.cdc.gov/pub/data/yrbs/1999/yrbs1999.dat 8 2001 2001 https://ftp.cdc.gov/pub/data/yrbs/2001/yrbs2001.dat 9 2003 2003 https://ftp.cdc.gov/pub/data/yrbs/2003/yrbs2003.dat 10 2005 2005 https://ftp.cdc.gov/pub/data/yrbs/2005/yrbs2005.dat 11 2007 2007 https://ftp.cdc.gov/pub/data/yrbs/2007/yrbs2007.dat 12 2009 2009 https://ftp.cdc.gov/pub/data/yrbs/2009/yrbs2009.dat 13 2011 2011 https://ftp.cdc.gov/pub/data/yrbs/2011/yrbs2011.dat 14 2013 2013 https://ftp.cdc.gov/pub/data/yrbs/2013/yrbs2013.dat 15 2015 2015 https://www.cdc.gov/healthyyouth/data/yrbs/files/yrbs2015.dat 16
2017年2017年 https://ftp.cdc.gov/pub/data/yrbs/sadc_2017/sadc_2017_district.dat 17 2017年2017年 https://ftp.cdc.gov/pub/data/yrbs/sadc_2017/sadc_2017_national.dat 18 2017年2017年 https://ftp.cdc.gov/pub/data/yrbs/sadc_2017/sadc_2017_state_a_m.dat 19 2017年2017年 https://ftp.cdc.gov/pub/data/yrbs/sadc_2017/sadc_2017_state_n_z.dat sas_url output_filename 1
https://ftp.cdc.gov/pub/data/yrbs/1991/YRBS_1991_SAS_Input_Program.sas U:// YRBSS / 1991 main.rds 2
https://ftp.cdc.gov/pub/data/yrbs/1993/YRBS_1993_SAS_Input_Program.sas U:// YRBSS / 1993 main.rds 3
https://ftp.cdc.gov/pub/data/yrbs/1995/NCHRBS_1995_SAS_Input_Program.sas U:// YRBSS / 1995 main.rds 4
https://ftp.cdc.gov/pub/data/yrbs/1995/YRBS_1995_SAS_Input_Program.sas U:// YRBSS / 1995 main.rds 5
https://ftp.cdc.gov/pub/data/yrbs/1997/YRBS_1997_SAS_Input_Program.sas U:// YRBSS / 1997 main.rds 6
https://ftp.cdc.gov/pub/data/yrbs/1998/AYRBS_1998_SAS_Input_Program.sas U:// YRBSS / 1998 main.rds 7
https://ftp.cdc.gov/pub/data/yrbs/1999/YRBS_1999_SAS_Input_Program.sas U:// YRBSS / 1999 main.rds 8
https://ftp.cdc.gov/pub/data/yrbs/2001/YRBS_2001_SAS_Input_Program.sas U:// YRBSS / 2001 main.rds 9
https://ftp.cdc.gov/pub/data/yrbs/2003/YRBS_2003_SAS_Input_Program.sas U:// YRBSS / 2003 main.rds 10
https://ftp.cdc.gov/pub/data/yrbs/2005/YRBS_2005_SAS_Input_Program.sas U:// YRBSS / 2005 main.rds 11
https://ftp.cdc.gov/pub/data/yrbs/2007/YRBS_2007_SAS_Input_Program.sas U:// YRBSS / 2007 main.rds 12
https://ftp.cdc.gov/pub/data/yrbs/2009/YRBS_2009_SAS_Input_Program.sas U:// YRBSS / 2009 main.rds 13
https://ftp.cdc.gov/pub/data/yrbs/2011/YRBS_2011_SAS_Input_Program.sas U:// YRBSS / 2011 main.rds 14
https://ftp.cdc.gov/pub/data/yrbs/2013/YRBS_2013_SAS_Input_Program.sas U:// YRBSS / 2013 main.rds 15
https://ftp.cdc.gov/pub/data/yrbs/2015smy/YRBS_2015_SAS_Input_Program.sas U:// YRBSS / 2015 main.rds 16
https://ftp.cdc.gov/pub/data/yrbs/sadc_2017/2017_sadc_national_sas_input_program.sas U:// YRBSS / 2017 main.rds 17
https://ftp.cdc.gov/pub/data/yrbs/sadc_2017/2017_sadc_sas_input_program.sas U:// YRBSS / 2017 main.rds 18 https://ftp.cdc.gov/pub/data/yrbs/sadc_2017/2017_sadc_states_a-m_sas_input_program.sas U:// YRBSS / 2017 main.rds 19 https://ftp.cdc.gov/pub/data/yrbs/sadc_2017/2017_sadc_states_n-z_sas_input_program.sas U:// YRBSS / 2017 main.rds将目录限制为仅2005-2015年
yrbss_cat <-子集(yrbss_cat,年%in%seq(2005,2015,2)) yrbss_cat目录年dat_url 10 2005 2005
https://ftp.cdc.gov/pub/data/yrbs/2005/yrbs2005.dat 11 2007 2007 https://ftp.cdc.gov/pub/data/yrbs/2007/yrbs2007.dat 12 2009 2009 https://ftp.cdc.gov/pub/data/yrbs/2009/yrbs2009.dat 13 2011 2011 https://ftp.cdc.gov/pub/data/yrbs/2011/yrbs2011.dat 14 2013 2013 https://ftp.cdc.gov/pub/data/yrbs/2013/yrbs2013.dat 15 2015 2015 https://www.cdc.gov/healthyyouth/data/yrbs/files/yrbs2015.dat sas_url output_filename 10
https://ftp.cdc.gov/pub/data/yrbs/2005/YRBS_2005_SAS_Input_Program.sas U:// YRBSS / 2005 main.rds 11
https://ftp.cdc.gov/pub/data/yrbs/2007/YRBS_2007_SAS_Input_Program.sas U:// YRBSS / 2007 main.rds 12
https://ftp.cdc.gov/pub/data/yrbs/2009/YRBS_2009_SAS_Input_Program.sas U:// YRBSS / 2009 main.rds 13
https://ftp.cdc.gov/pub/data/yrbs/2011/YRBS_2011_SAS_Input_Program.sas U:// YRBSS / 2011 main.rds 14
https://ftp.cdc.gov/pub/data/yrbs/2013/YRBS_2013_SAS_Input_Program.sas U:// YRBSS / 2013 main.rds 15 https://ftp.cdc.gov/pub/data/yrbs/2015smy/YRBS_2015_SAS_Input_Program.sas U:// YRBSS / 2015 main.rds下载yrbss微数据
lodown(“ yrbss”,yrbss_cat)在本地下载yrbss
从URL下载 “ https://ftp.cdc.gov/pub/data/yrbs/2005/yrbs2005.dat”提交 'C:\ Users \ JAIMIN〜1 \ AppData \ Local \ Temp \ Rtmpemmaly \ file684c13a73873'
下载问题 'https://ftp.cdc.gov/pub/data/yrbs/2005/yrbs2005.dat'
下载问题 'https://ftp.cdc.gov/pub/data/yrbs/2005/yrbs2005.dat'
下载问题 'https://ftp.cdc.gov/pub/data/yrbs/2005/yrbs2005.dat'
R版本3.4.0(2017-04-21)平台:x86_64-w64-mingw32 / x64(64位) 在以下环境下运行:Windows> = 8 x64(内部版本9200)
Matrix产品:默认
语言环境:[1] LC_COLLATE = English_United States.1252 LC_CTYPE = English_United States.1252 LC_MONETARY = English_United States.1252 [4] LC_NUMERIC = C
LC_TIME =英语_美国。1252附带的基本软件包:[1]网格统计图形grDevices utils数据集方法基础
其他附加软件包:[1] lodown_0.1.0 survey_3.33-2
Survival_2.41-3 Matrix_1.2-9通过名称空间(未附加)加载:[1] httr_1.3.1
编译器_3.4.0 R6_2.2.2工具_3.4.0 RCurl_1.95-4.11 curl_2.6 yaml_2.1.14花键_3.4.0 [9]摘要_0.6.16
bitops_1.0-6点阵_0.20-35lodown现在意外退出。托管网站 可公开下载的微数据经常更改,有时 更改会导致该软件损坏。如果下面的错误调用堆栈 似乎是您的互联网连接出现问题,请验证 您的连接,然后重试下载。否则,请打开一个新的 在
https://github.com/ajdamico/asdfree/issues
发行, 此错误调用堆栈的内容以及您的输出sessionInfo()
。[[1]] lodown(“ yrbss”,yrbss_cat)
[[2]] withCallingHandlers(目录<-load_fun(data_name = data_name, 目录...),错误=函数(e){ 打印(sessionInfo()) 如果(grepl(“无法分配大小的向量”,e)) 留言(memory_note) 否则,如果(grepl(“必须指定参数”,e)) 消息(parameter_note) 否则,如果(grepl(“要安装”,e)) 消息(installation_note) 其他{ 讯息(unknown_error_note) 打印(sys.calls()) }}
[[3]] load_fun(数据名称=数据名称,目录...)
[[4]]茶(目录[i,“ dat_url”],tf_fn,mode =“ wb”)
[[5]] httr_filesize(this_url,尝试次数,sleepsec)
[[6]] stop(paste0(“ httr :: HEAD('”,url,“')\ n在”, 初始尝试 “尝试”))
[[7]] .handleSimpleError(function(e){ 打印(sessionInfo()) 如果(grepl(“无法分配大小的向量”,e)) 留言(memory_note) 否则,如果(grepl(“必须指定参数”,e)) 消息(parameter_note) 否则,如果(grepl(“要安装”,e)) 消息(installation_note) 其他{ 讯息(unknown_error_note) 打印(sys.calls()) }},“ httr :: HEAD('https://ftp.cdc.gov/pub/data/yrbs/2005/yrbs2005.dat')\ n失败 3次尝试”, 报价(httr_filesize(this_url,尝试次数,sleepsec)))
[[8]] h(simpleError(msg,call))
httr_filesize(this_url,尝试次数,sleepsec)错误:httr :: HEAD( 'https://ftp.cdc.gov/pub/data/yrbs/2005/yrbs2005.dat')在3后失败 尝试目录年份
dat_url 10 2005 2005
https://ftp.cdc.gov/pub/data/yrbs/2005/yrbs2005.dat 11 2007 2007 https://ftp.cdc.gov/pub/data/yrbs/2007/yrbs2007.dat 12 2009 2009 https://ftp.cdc.gov/pub/data/yrbs/2009/yrbs2009.dat 13 2011 2011 https://ftp.cdc.gov/pub/data/yrbs/2011/yrbs2011.dat 14 2013 2013 https://ftp.cdc.gov/pub/data/yrbs/2013/yrbs2013.dat 15 2015 2015 https://www.cdc.gov/healthyyouth/data/yrbs/files/yrbs2015.dat sas_url output_filename case_count 10
https://ftp.cdc.gov/pub/data/yrbs/2005/YRBS_2005_SAS_Input_Program.sas U:// YRBSS / 2005 main.rds NA 11
https://ftp.cdc.gov/pub/data/yrbs/2007/YRBS_2007_SAS_Input_Program.sas U:// YRBSS / 2007 main.rds NA 12
https://ftp.cdc.gov/pub/data/yrbs/2009/YRBS_2009_SAS_Input_Program.sas U:// YRBSS / 2009 main.rds NA 13
https://ftp.cdc.gov/pub/data/yrbs/2011/YRBS_2011_SAS_Input_Program.sas U:// YRBSS / 2011 main.rds NA 14
https://ftp.cdc.gov/pub/data/yrbs/2013/YRBS_2013_SAS_Input_Program.sas U:// YRBSS / 2013 main.rds NA 15 https://ftp.cdc.gov/pub/data/yrbs/2015smy/YRBS_2015_SAS_Input_Program.sas U:// YRBSS / 2015 main.rds NA >
答案 0 :(得分:0)
库(httr)set_config(config(ssl_verifypeer = 0L))#这两行修复了对等证书错误,然后代码开始工作。