Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Print Plot of String Equation in R

$
0
0

I am new to R and have this pretty simple question.

I am importing an equation from a json file called run.json. The JSON looks something like this.

    "equations": {
        "spec": {
            "expression": "x*x*x+2*x",
            "seed": 0,
            "range": 100
        }
    }

Im loading in the file like so

library("rjson")
result <- fromJSON(file = "run.json")

png('plot-spec.png', width=4, height=4, units='in', res=300)
specExpression = result$equations$spec$expression
seed = result$equations$spec$seed
range = result$equations$spec$range

# using noquote to remove quotes from the specExpression as it came in as a string
specEquation = function(x){noquote(specExpression)}
curve(
specEquation,
    from=seed,
    to=range,
    ylab="Y",
    xlab="X")

I keep getting the following error 'expr' did not evaluate to an object of length 'n'. Not too sure what to do with it


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>