Select to view content in your preferred language

Can arc.write be used for R data frame made from excel?

2205
6
Jump to solution
09-05-2018 05:57 PM
KentaOkuyama
Occasional Contributor

Hello, I've just started using "arcgisbinding" package in R.

I'm trying some basic data transfer between R and ArcGIS Pro, and I have one question.

Can I write R data.frame (which I read from excel) to ArcGIS? 

After I have seen some resources, looks like only the object I read in R from ArcGIS object can be transferred back. 

But if there is a way to transfer my R data frame object (which are originally made from excel, csv, etc.) to Arc GIS, this would be great.

*** R data frame object I want to transfer to Arc GIS does not have any spatial information. It has two columns "ID" and "address" as string. So I want to transfer it to ArcGIS gdb table not as feature class. 

I would greatly appreciate if anyone can help out with this!

My code I attempted in R:

df <- read_excel("G:/AllData/Kyuson_Aza/Kyuson_AzaListFinal.xlsx")

df2 <- df[2,4]
# export this data frame to Arc GIS
arc.write(path = "C:/Users/kenta/Documents/ArcGIS/Projects/MyProject2/MyProject2.gdb", data = df2)

The error I got:

Error in .call_proxy("arc_export2dataset", path, pairlist(data = data, : dataset already exists

0 Kudos
1 Solution

Accepted Solutions
ShaunWalbridge
Esri Regular Contributor

Hello Kenta,

It looks like you may be trying to create a new feature class, and if that's the case, you'll want to give a fully qualified name for the path. The first parameter right now is the path to the File Geodatabase, but you'll also want a feature class name, such as:

arc.write(path = "C:/Users/kenta/Documents/ArcGIS/Projects/MyProject2/MyProject2.gdb/Kyuson_Aza", data = df2, overwrite = TRUE)

There are more examples of paths that are valid for arc.write in the arc.write package documentation that may prove helpful.

Cheers,

Shaun

View solution in original post

6 Replies
MarjeanPobuda
Deactivated User

Hi Kenta,

You can transfer your R data frame object to ArcGIS as a table like you describe. Based on your code, it looks like you might just need a minor modification or two. 

One problem might be the subset you have created. 

df <- read_excel("G:/AllData/Kyuson_Aza/Kyuson_AzaListFinal.xlsx")

df2 <- df[2,4]

In this case, you are asking for object df2 to contains the element in the second row and fourth column. This means this new object would no longer be a data frame but rather, the type of element contained in that location. In which case, the arc.write() function would not recognize it as a valid object to write. 

However, if you made a larger subset that still was a data frame:

df <- read_excel("G:/AllData/Kyuson_Aza/Kyuson_AzaListFinal.xlsx")

df2 <- df[2:3,4:6]

You could write it back using the following line:

arc.write(path = "C:/Users/kenta/Documents/ArcGIS/Projects/MyProject2/MyProject2.gdb", data = df2, overwrite = TRUE)

That last parameter is key. Based on the error you provide, it seems you may have already written a table but, are now trying to overwrite it and are currently being prevented from doing so. 

I hope this helps!

-Marjean

KentaOkuyama
Occasional Contributor

Hi Marijean, 

Thank you so much for your comments. That was really helpful.

I made sure to create R data frame by following code.

df <- read_excel("G:/AllData/Kyuson_Aza/Kyuson_AzaListFinal.xlsx")

df2 <- df[c("year","address")]

Then I have attempted this code:

arc.write(path = "C:/Users/kenta/Documents/ArcGIS/Projects/MyProject/MyProject.gdb", data = df2, overwrite = TRUE)

 

It ran without errors. But I still could not get gdb table in my ArcGIS project database.

I'm sorry it's in Japanese, but I'm attaching the screen shots what happened before and after I ran my code.

Before I ran my R code:

This is before I ran my arc.write code

After I ran my R code:

A new MyProject.gdb appeared, but nothing in those databases. 

This is after I ran my arc.write code

I appreciate for your additional helps and suggestions.

Best, 

Kenta

0 Kudos
ShaunWalbridge
Esri Regular Contributor

Hello Kenta,

It looks like you may be trying to create a new feature class, and if that's the case, you'll want to give a fully qualified name for the path. The first parameter right now is the path to the File Geodatabase, but you'll also want a feature class name, such as:

arc.write(path = "C:/Users/kenta/Documents/ArcGIS/Projects/MyProject2/MyProject2.gdb/Kyuson_Aza", data = df2, overwrite = TRUE)

There are more examples of paths that are valid for arc.write in the arc.write package documentation that may prove helpful.

Cheers,

Shaun

KentaOkuyama
Occasional Contributor

Hi Shaun, 

It worked out when adding the name of new feature class as you suggested!

Thank you so much, I really appreciate it.

Best, 

Kenta

0 Kudos
ShaunWalbridge
Esri Regular Contributor

Hi Kenta,

Great! Glad Marjean and I were able to help you.

Best of luck working with ArcGIS and R,

Shaun

KentaOkuyama
Occasional Contributor

Yes, thank you Shaun and Marjean!

Kenta

0 Kudos