Вопрос

I set up a local OpenCPU single-user server using RStudio. I also create my own R package(Package name: test) which includes only a simple test.R file. The source code is

f1 <- function(x, y) {x+y}

I started the OpenCPU server by typing library(opencpu) in RStudio's console. I got the following print.

Initiating OpenCPU server...
OpenCPU started.
[httpuv] http://localhost:6067/ocpu
OpenCPU single-user server ready.

I was able to run the script by typing curl http://localhost:6067/ocpu/library/test/R/f1 -d "x=33&y=3".

But when I tried to display the R script(test.R) by typing curl http://localhost:6067/ocpu/library/test/R/test.R, it printed

object 'test.R' not found

In call: get(reqobject, paste("package", reqpackage, sep = ":"), inherits = FALSE)

In addition, It's failed when I ran the test.R script by typing curl http://localhost:6067/ocpu/library/test/R/test.R -X POST -d "x=3&y=4". Could I run the script like that?

Could anyone help with this? Thanks.

Это было полезно?

Решение

When you install the R package, scripts under /R are turned into functions/objects. To read the source of the function, just do on of these:

curl http://localhost:6067/ocpu/library/test/R/f1/print
curl http://localhost:6067/ocpu/library/test/R/f1/ascii
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top