rvest::set_values() returning error - r

I'm trying to use the set_values() function to insert a company name using this website:
https://www.unternehmensregister.de/ureg/search1.4.html
Unfortunately, after
search <- html_form(read_html("https://www.unternehmensregister.de/ureg/search1.4.html"))[[1]]
the command
set_values(search, searchRegisterForm:companyPublicationsCompanyName - "Daimler")
gives an error.
Error in
set_values(search,searchRegisterForm:companyPublicationsCompanyName -
: object 'searchRegisterForm:companyPublicationsCompanyName' not
found
It would be great if someone can help me with that!

Related

R - using XPath in rvest gives error "Unexpected character"

I have a website that I'm trying to scrap . I've found the proper html tag that I want to scrap and copied its XPath that looks like this:
/html/body/div[1]/div[2]/main/div/div[2]/div[1]/div[2]/div[3]/ul
Next I use rvest:
library(rvest)
my_website <- read_html("http://www...") # a full link to the website
links <- html_nodes(my_website, "/html/body/div[1]/div[2]/main/div/div[2]/div[1]/div[2]/div[3]/ul/")
and I get the following error:
Error in tokenize(css) : Unexpected character '/' found at position 1.
I'm not really fluent in webscrapping, so could anyone please explain me what I am doing wrong?

Invalid formula error in R - xtabs function giving environment issure

When trying to run this (or any other) command
xtabs(ugdata$response, ugdata$Equity, data=ugdata)
I keep receiving this error
Error in formula.default(object, env = baseenv()) : invalid formula
I have been looking around all day, including similar posts on this website, but I cannot find a solution to help me fix this.
Any help would be greatly appreciated
I believe the error is in the syntax. Please try:
xtabs(ugdata$response ~ ugdata$Equity, data = ugdata)

Error in gmax(<my_variable>) : object 'my_variable' not found

I'm running the following code, and I get the error mentioned in the title when I run it.
dt.placements[,.(first.received = min(file.dt)
,last.received = max(file.dt)
,SUB_ACCT_NO_SBB=max(SUB_ACCT_NO_SBB)
)
,by=.(SUB_ACCT_NO_SBB,EQP_SERIAL_EQP)]
Can someone please explain to me why I am getting this message and how to fix my code. This code was working for me before I added the 3rd line--I added it to try to take out duplicates in the results.

quantmod - getQuote() - '403 Forbidden'

I found an answer to my own question (see below). Still need help.
In the same package, quantmod, there is an option called getSymbol.google.
Nevertheless,
If I use it to get Microsoft value, for example, it works all right
getSymbols.google('MSFT', environment() , src="google", from = (Sys.Date() - 1))
[1] "MSFT"
But, I can´t make it work on a currency pair;
getSymbols.google("GBPUSD", environment() , src="google", from = (Sys.Date() - 1))
Error in download.file(paste(google.URL, "q=", Symbols.name, "&startdate=", :
cannot open URL 'http://finance.google.com/finance/historical?q=GBPUSD&startdate=Nov+02,+2017&enddate=Nov+03,+2017&output=csv'
In addition: Warning message:
In download.file(paste(google.URL, "q=", Symbols.name, "&startdate=", :
cannot open URL 'http://finance.google.com/finance/historical?q=GBPUSD&startdate=Nov+02,+2017&enddate=Nov+03,+2017&output=csv': HTTP status was '400 Bad Request'
Any ideas?
Good morning,
Since the 1ts of November i´m having trouble with the function getQuote from Yahoo. Is a function inside the package "quantmod", which uses yahoo API to request the information.
The description of the function is as follows; Fetch current stock quote(s) from specified source. At present this only handles sourcing quotes from Yahoo Finance, but it will be extended to additional sources over time.
In r, i´m getting the following error; "HTTP status was '403 Forbidden'"
I´ve look on my browser and the error comes from the following error in Yahoo web page "Fetch current stock quote(s) from specified source. At present this only handles sourcing quotes from Yahoo Finance, but it will be extended to additional sources over time."
Does anybody know how to solve ir, or, any alternatives to the function getQuote()
Here is an example from RStudio
getQuote("AAPL")
Error in download.file(paste("https://finance.yahoo.com/d/quotes.csv?s=", :
cannot open URL 'https://finance.yahoo.com/d/quotes.csv?s=AAPL&f=d1t1l1c1p2ohgv'
In addition: Warning message:
In download.file(paste("https://finance.yahoo.com/d/quotes.csv?s=", :
cannot open URL 'https://finance.yahoo.com/d/quotes.csv?s=AAPL&f=d1t1l1c1p2ohgv': HTTP status was '403 Forbidden'
Thanks
seems that yahoo has discontinued this service. Anyone aware of a alternative for yahoo (I'd rather not have to webscrape yahoo for this)
rob
I ran into the same problem... it's kludgey but as a workaround to get the end-of-day value, I have found this to work for now:
Instead of getQuote() to get the Last price (which doesn't seem to work from Yahoo anymore):
underlying<-"AAPL"
quote.last <-getQuote(underlying)$Last
I use "getSymbols" which still works-- throws it into a new data frame, and I pull out the value I want from that:
Hx<-getSymbols(underlying,from=Sys.Date()-1) # allows me to not have to retain the ticker name if I do this across many tickers
quote.last<-as.double(tail(Cl(get(Hx)),1)) # Closing price value from last row of data
rm(list=Hx) # throw away the temporary data frame with quote history
I'm sure the's a more elegant way to do it, but this is what fell out of my brain as a quick workaround that got it done... sadly that doesn't get things like the Bid and Ask that getQuote does.

Bloomberg data retrieval in R : Invalid override field id specified error

I would like to retrieve power hedging data using Rbbg bloomberg package in R and I know this formula works in excel :
=BDH("VATT SS Equity","BI_%_ELECTRIC_POWER_HEDGED","01/01/2000","","GEOGRAPHIC_LOCATION_OVERRIDE=EUCN","BI_CONTRACT_MATURITY_OVERRIDE=CY12","FUND_PER=Q")
But when I try this in R :
conn<-blpConnect(log.level="off")
data<-bdh(conn,"VATT SS Equity","BI_PER_ELECTRIC_POWER_HEDGED","20000101","","GEOGRAPHIC_LOCATION_OVERRIDE=EUCN","BI_CONTRACT_MATURITY_OVERRIDE=CY12","FUND_PER=Q")
I get the following error message :
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
org.findata.blpwrapper.WrapperException: response error: Invalid override field id specified [nid:217]
What should I change in the formula to make it work ?
Thanks
Edit: Indeed it is BI_PCT_ELECTRIC_POWER_HEDGED, however the problem does not come from here but from the overrides.
This returns an empty variable for me, but it doesn't throw an error so it might get you on the right track.
The way you specify options is different in the current version it seems.
data<-bdh(conn,"VATT SS Equity", "BI_PER_ELECTRIC_POWER_HEDGED","20000101","",
override_fields=c("GEOGRAPHIC_LOCATION_OVERRIDE",
"BI_CONTRACT_MATURITY_OVERRIDE",
override_values=c("EUCN","CY12"),
option_names="periodicitySelection",
option_values="QUARTERLY")
The doc where I found the correct syntax is here: RBloomberg. It was written in 2010 for the predecessor package (before Bloomberg complained about using their name) but I guess it works! I think the convention of enumerating the list of option names then the option values is odd compared to your assumption that OPTION=VALUE was correct, but there you go.

Resources