Sf: Rscript can't read fields from stored data objects

Created on 1 Mar 2018  路  4Comments  路  Source: r-spatial/sf

I can run queries on specific fields of packaged data objects in an interactive R session:

library(concaveman)
class(points$k)
head(points$k > 4)

[1] "integer"
[1] TRUE TRUE TRUE TRUE TRUE TRUE

However, in an Rscript command it seems I cannot:

Rscript -e "library(methods);library(sf);library(concaveman); class(points$k); head(points$k > 4)"

Linking to GEOS 3.5.1, GDAL 2.2.2, proj.4 4.9.2
[1] "sf" "data.frame"
Error in Ops.sfc(left, right) : operation > not supported
Calls: head -> Ops.data.frame -> eval -> eval -> Ops.sfc
Execution halted

Most helpful comment

In bash, the $ needs escaping to protect it from the shell:

echo $mpg
echo "mtcars$mpg"
Rscript -e "mtcars\$mpg"

if double quotes are used; if single quotes, the $ is protected:

Rscript -e 'mtcars$mpg'

All 4 comments

It seems the $ method does not get exported.

Rscript -e 'library(methods);library(sf);library(concaveman); class(points[["k"]]); head(points[["k"]] > 4)'

works.

To be clear, this is not caused by sf just my ignorance about Rscript.

Rscript -e "mtcars$mpg"

vs

Rscript -e "mtcars[['mpg']]"

In bash, the $ needs escaping to protect it from the shell:

echo $mpg
echo "mtcars$mpg"
Rscript -e "mtcars\$mpg"

if double quotes are used; if single quotes, the $ is protected:

Rscript -e 'mtcars$mpg'

Right,

Rscript -e 'library(methods);library(sf);library(concaveman); class(points$k); head(points$k > 4)'

works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tiernanmartin picture tiernanmartin  路  3Comments

gregmacfarlane picture gregmacfarlane  路  4Comments

happyshows picture happyshows  路  3Comments

kendonB picture kendonB  路  4Comments

kendonB picture kendonB  路  3Comments