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
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!
Most helpful comment
In
bash, the$needs escaping to protect it from the shell:if double quotes are used; if single quotes, the
$is protected: