Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Fatma
New Member

Failed to load R script

I have this R script and he run succefully but when i would to load in Power BI, i get that error message:

this is my code: 

library(rvest)
> library(httr)
> sess <- html_session("http://www.atb.com.tn/", user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.39 Safari/537.36"))
> pg <- jump_to(sess, "http://www.atb.com.tn/devise")
> dat <- content(pg$response, as="parsed")
> mydata= html_table(html_nodes(dat, "table")[[2]], header=TRUE)

And that the error message:

 

 

Détails : « ADO.NET : Erreur du script R.
Le chargement a nÚcessitÚ le package : xml2
Error in as.vector(x, "list") :
cannot coerce type 'environment' to vector of type 'list'
Calls: html_table ... <Anonymous> -> lapply -> as.list -> as.list.default
ExÚcution arrÛtÚe

5 REPLIES 5
ankitpatira
Community Champion
Community Champion

@Fatma @beno

 

Adding library(methods) reference has worked. Since data frame returned has duplicate column names it would again error out so changed header to False (it will return header as first row and you can again change that to headers in power bi) and also fill = True. so end script which works will be as follows,

 

library(rvest)
library(methods)
library(httr)
sess <- html_session("http://www.atb.com.tn/", user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.39 Safari/537.36"))
pg <- jump_to(sess, "http://www.atb.com.tn/devise")
dat <- content(pg$response, as="parsed")
mydata= html_table(html_nodes(dat, "table")[[2]], header=FALSE, fill=TRUE)

Many thanks

beno
Frequent Visitor

Hi, 

 

Any news about this issue, as I have the same error message:

 

Details: "ADO.NET: R script error.
Loading required package: xml2
Warning message:
'html' is deprecated.
Use 'read_html' instead.
See help("Deprecated") 
Error in as.vector(x, "list") : 
  cannot coerce type 'environment' to vector of type 'list'
Calls: %>% ... <Anonymous> -> lapply -> as.list -> as.list.default
Execution halted
"

 

The installation folder is:

C:\Program Files\R\R-3.3.1

 

The downloaded binary packages (add-on packages) are in:
C:\Users\dev\AppData\Local\Temp\RtmpCYKMBC\downloaded_packages

 

The '.libPaths()' will give the following paths:

[1] "C:/Users/dev/Documents/R/win-library/3.3"
[2] "C:/Program Files/R/R-3.3.1/library"

 

As during installing add-on, I have chosen to have a personal library:

Would you like to use a personal library instead? Yes

 

BR

beno
Frequent Visitor

Isn't there any reply to his post?

Anonymous
Not applicable

@beno I'm not very familiar with "R", other than people like to make pirate jokes when studying and applying it. I did find this forum with a similiar question, it sounds like it could assist you.

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.