在此先感谢您的帮助。本质上,我正在编写一个构建 URL 的程序,该 URL 将提供一个 CSV 文件。该程序要求用户提供几个输入,然后将这些输入附加到基本 URL。我遇到的问题是,当我尝试将它们粘贴到 URL 中时,每个用户输入之间都会增加一个空格。问题出在#Build URL 行中。
这是代码
#URL Builder for Yahoo Finance
#Requests Input from User, Builds URL, downloads csv.file from site
#Requests are for:
#Ticker (2-4 letter - character string)
#Start Month (00 - 11 integer)
#Start Day (1 - 31 integer)
#Start Year (Four digit integer)
#End Month (00 - 11 integer)
#End Day (1 - 31 integer)
#End Year (Four digit integer)
#Functions
Get_Ticker <- function(){readline("Please enter a Ticker:>>> ")}
Get_Month_Begin <- function(){as.numeric(readline("Enter the start month (MM):>>> "))}
Get_Day_Begin <- function(){as.numeric(readline("Enter the start day (1-31) :>>> "))}
Get_Year_Begin <- function(){as.numeric(readline("Enter the start year (YYYY) :>>> "))}
Get_Month_End <- function(){as.numeric(readline("Enter the end month (MM) :>>> "))}
Get_Day_End <- function(){as.numeric(readline("Enter the end day (1-31) :>>> "))}
Get_Year_End <- function(){as.numeric(readline("Enter the end year :>>> "))}
#Function Calls
Ticker <- Get_Ticker()
Month_Begin <- Get_Month_Begin()
Day_Begin <- Get_Day_Begin()
Year_Begin <- Get_Year_Begin()
Month_End <- Get_Month_End()
Day_End <- Get_Day_End()
Year_End <- Get_Year_End()
#Build URL
#Example URL: ichart.finance.yahoo.com/table.csv?s=DVN&a=00&b=1&c=1992&d=11&e=31&f=2013&g=d&ignore=.csv
CSV_Base_URL <- "ichart.finance.yahoo.com/table.csv?s="
CSV_URL_Complete <- paste(CSV_Base_URL,Ticker,"&a=",Month_Begin,"&b=",Day_Begin,"&c=",Year_Begin,"&d=",Month_End,"&e=",Day_End,"&f=",Year_End,"&g=d&ignore=.csv",sep="")
#Download CSV
Yahoo_Finance_TBL <- read.csv(CSV_URL_Complete)
#Write CSV File
write.csv(Yahoo_Finance_TBL, file="Yahoo_Finance_File", row.names=FALSE)
再次,我非常感谢您的帮助。
尊敬,
乔纳森