R.NET出错“错误:'arch = i386'没有安装包'RMySQL'”

时间:2014-06-18 12:37:55

标签: c# r rmysql

当我使用C#代码运行Rscript时,我收到了我在主题中提到的错误。实际上RMySQL包正确安装在我的系统中(Windows 7 64位),我可以直接从Rconsole运行脚本。但是当从C#代码调用时,我收到此错误。请帮我找到相同的解决方案。谢谢

这是我的C#代码

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using RDotNet;

  namespace hottopics_new
  {
   public partial class hottopic : System.Web.UI.Page
   {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        REngine.SetEnvironmentVariables();
        REngine engine = REngine.GetInstance();
        engine.Initialize();
        var hottopic = engine.Evaluate("source('E:/******/******/Rscript/hottopics.R')").AsDataFrame();
        var words = hottopic[1].AsCharacter().ToArray();
        var freq = hottopic[2].AsCharacter().ToArray();
        Console.WriteLine(words);
        Console.WriteLine(freq);
        engine.Dispose();
    }
  }
 }

```

我在上面的代码中出现以下错误 " var hottopic = engine.Evaluate("来源(' E:/ ** / ** / R script / hottopics.R& #39)&#34)AsDataFrame();"

这是我的R剧本

user_id = 39988 library(RMySQL) con = dbConnect(MySQL(), user='****', password='****', dbname='****', host='*********') # Add the text mining library for using the removeWords and stopwords functions library(tm) setwd("E:/*****/****/R script") sqlQuery <- paste("SELECT b.user_id,a.user_social_account_id,a.content FROM mydb.updates a INNER JOIN mydb.user_social_accounts b ON a.user_social_account_id = b.id WHERE a.user_social_account_id IN (SELECT id FROM mydb.user_social_accounts WHERE user_id =",user_id,')',sep = "") updates <- dbGetQuery(con,statement=sqlQuery) dbDisconnect(con) words <- read.csv("stopwords.csv",colClasses = "character") # Convert the 'words' object from data.frame to charcter vector format words <- words$Words updates$content <- tolower(updates$content) content <- updates$content # Split each words in the content and saved in a character vector format content <-unlist(strsplit(content, split=" ")) # Remove all the stopwords,numbers and symbols from it content <- removeWords(content,c(stopwords("english"),stopwords("SMART"),words)) content <- gsub("[^a-zA-Z]", "", content) # Count each words frequency using the 'table' function and store the result in data.frame format word_count <- as.data.frame(table(content)) names(word_count) <- c("Word","Freq") # Removing the blank character from the result that comes when removing the symbols and numbers word_count <- word_count[-(word_count$Word == ""),] # Order the word_count data frame in the descending order of Frequency of words word_count <- word_count[order(-word_count$Freq,word_count$Word),] head(word_count,10)

1 个答案:

答案 0 :(得分:0)

这可能是known issue due to the way IIS handles environment variables。与此问题相关的问题有一个由该问题的记者亲切提出的解决方法。

如果解决方法解决了这个问题,请将此标记为已解答; ASP.NET + R.NET的问题是一个反复出现的主题。