首页 \ 问答 \ 使用dsn使用RODBC将R连接到MySQL(connect R to MySQL with RODBC using dsn)

使用dsn使用RODBC将R连接到MySQL(connect R to MySQL with RODBC using dsn)

简短版本:我试图弄清楚如何在odbcConnect()函数中使用dsn参数来连接MySQL数据库。

更长的版本:如果这是一个无知的问题,我会道歉。 我没有在标签下找到SO搜索的答案。 我不是R的新手,虽然我不是世界上最重要的专家。 我是MySQL新手。 我一直在努力学习它。

我希望能够在R中创建表格等,并将它们写入MySQL中的数据库,然后能够在以后从中进行选择并将选定的记录读回R进行分析。 我可以在MySQL中创建一个数据库,选择,导出一个文本文件,然后将该文件读入R中,但我宁愿能够从R做所有事情。为此,我安装了RODBC以便能够将R连接到MySQL直。 我知道我需要使用odbcConnect()函数,但是我不明白为dsn参数添加什么来执行此操作,并且无法从wiki帮助文件中找出它。

细节 (如果需要):

I did not establish a uid or password when I set up MySQL

Versions used:          Windows XP;     R 2.10.1;     MySQL 5.5
Locations of exe files: C:\Program Files\MySQL\MySQL Server 5.5\bin  
                        C:\Program Files\R\R-2.10.1\bin  

我希望我需要相当基本的建议 - 例如,最好假设我甚至不知道dsn代表什么(即使这不是真的)。 任何帮助表示赞赏。 提前致谢。


Short version: I'm trying to figure out how to use the dsn argument in the odbcConnect() function to connect to a MySQL database.

Longer version: I appologize if this is an ignorant question. I didn't find an answer on SO searching under the tags. I'm not new to R, although I'm not the world's foremost expert. I am new to MySQL. I have been trying to learn it on my own.

I would like to be able to create tables and such in R and write them to a database in MySQL and then be able to select from them later and read the selected records back into R for analysis. I can create a database in MySQL, select, export a text file, & read that file into R now, but I would rather be able to do everything from R. For this purpose, I installed RODBC to be able to connect R to MySQL directly. I understand that I need to use the odbcConnect() function, but I do not understand what to put for the dsn argument to do this, and haven't been able to figure it out from the wiki or the help file.

Details (if needed):

I did not establish a uid or password when I set up MySQL

Versions used:          Windows XP;     R 2.10.1;     MySQL 5.5
Locations of exe files: C:\Program Files\MySQL\MySQL Server 5.5\bin  
                        C:\Program Files\R\R-2.10.1\bin  

I expect I need fairly basic advice--e.g., it might be best to assume I don't even know what dsn stands for (even though that's not actually true). Any help is appreciated. Thanks in advance.


原文:https://stackoverflow.com/questions/9539544
更新时间:2024-05-05 16:05

最满意答案

你根本不需要拥有$myID 。 您可以在promise中使用$index ,因为它已经被限制在循环块中。 这是一个工作修改(..with严格):

my @result = do for 0 .. 2 -> $index {
    start {
        say "======> $index\n";

        my $rsSocket = IO::Socket::INET.new:
            localhost => 'localhost',
            localport => 1234 + $index,
            listen    => 1;

        while $rsSocket.accept -> $rsConnection {
            say "Promise $index accepted connection";
            while $rsConnection.recv -> $stuff {
                say "promise $index Echoing $stuff";
                $rsConnection.print($stuff);
            }
            $rsConnection.close;
        }
    }
}

await @result;

有了这种照顾,我觉得有一种冲动指出, no strict使用似乎是非常不必要的。 这不仅会让你打开这些奇怪的范围问题,而且在你的例子中你完全没有得到什么。

对未修改的代码严格重新启用并修复两个编译错误显示只保存了四个按键 - 代价是无论您在此输入问题的键是多少。


You don't really need to have a $myID at all. You can just use $index in the promise because it has already been scoped to the loop block. Here's a working modification (..with strict on):

my @result = do for 0 .. 2 -> $index {
    start {
        say "======> $index\n";

        my $rsSocket = IO::Socket::INET.new:
            localhost => 'localhost',
            localport => 1234 + $index,
            listen    => 1;

        while $rsSocket.accept -> $rsConnection {
            say "Promise $index accepted connection";
            while $rsConnection.recv -> $stuff {
                say "promise $index Echoing $stuff";
                $rsConnection.print($stuff);
            }
            $rsConnection.close;
        }
    }
}

await @result;

With that taken care of I feel the urge to point out that using no strict seems very unnecessary. Not only does it leave you open to weird scope issues like these, but you gain basically nothing from doing it in your example.

Re-enabling strict on your unmodified code and fixing the two compile errors shows have only saved a total of four keystrokes -- at the expense of however many keys you used typing up your question here.

相关问答

更多
  • 没有perl6,并且有许多Perl 6编译器。 Perl 6有一个语法,尽管它是用Perl 6编写的 ,所以只要你能理解,它就会告诉你一切你需要知道的东西。 我刚刚问拉里这个问题,因为我在圣保罗Perl Workshop上午餐时坐在他对面。 他说现在是“只有Perl 6可以解析Perl 6”,在Perls上都有大写字母,这意味着与原始语句不同。 你不需要一个特定的程序来完成这个任务,但是因为Perl 6的目标是一个标准和许多实现。 没有“perl6”,虽然Larry在他今天的演讲中已经把他的Rakudo弄成 ...
  • 根据我的理解,goroutines是一个非常低级的结构。 Perl中的大多数东西都不是很低级。 最接近您想要的可能是直接使用Threads 。 my @r = do for ^100 { # currently aborts if it's much over 100 Thread.start: { .say; sleep 3 }; } # The implementation may actually create several threads # for this construct @r>>. ...
  • 一个不太好的沉默失败掩盖了你将一个类型对象传递给getmouse()的事实。 我只是通过用第18行的$event.x替换$event.perl作为信息捕鱼探险来发现它。 这样做会产生; user@Ubuntu-iMac:~$ ./getmouse.p6 ok: -1 Invocant requires an instance of type NCurses::MEVENT, but a type object was passed. Did you forget a .new? in block ...
  • 是的, then确实返回一个新的promise( x ),它解析为回调的结果 - 如果该结果( p2 )是一个promise,它的状态将被采用,以便x在p2满足时满足并在p2拒绝时拒绝。 另见这里 ,也许阅读Promises / A +规范 。 Yes, then does return a new promise (x) that resolves to the result of the callback - and if that result (p2) is a promise its state ...
  • moar是一个后端。 要获得特定的Rakduo版本,您还必须指定它: rakudobrew build moar 2017.07 rakudobrew build moar 2017.04.3 完成此操作后,您可以选择使用哪一个: rakudobrew switch moar-2017.04.3 如果您有兴趣,请运行rakudobrew list-available以获取所有可用的Rakudo版本和后端的列表。 对大多数用户的说明 :除非你真的需要Rakudo的“前沿”版本,否则我建议使用相对容易安装和 ...
  • 你根本不需要拥有$myID 。 您可以在promise中使用$index ,因为它已经被限制在循环块中。 这是一个工作修改(..with严格): my @result = do for 0 .. 2 -> $index { start { say "======> $index\n"; my $rsSocket = IO::Socket::INET.new: localhost => 'localhost', loca ...
  • 内嵌:: Perl5的 截至2014年底,对于大多数人来说,对于大多数人来说, Inline :: Perl5是在P6中使用P5代码的方式,反之亦然,包括在P6中use P5库。 Inline :: Perl5在MoarVM中适当地打包并包装一个常规的perl5解释器,以便P6编译器Rakudo可以与P5互操作。 该组合已经支持: 在Perl 6中use Perl 5模块,包括使用XS的模块 在P6中操纵P5对象,反之亦然 在P6中编写Perl 5类的子类 九,该模块的作者,在他创办Inline :: Pe ...
  • 对then的调用也会返回一个promise。 然后,您可以将其传递给您的数组而不是原始的承诺。 这样你的$q.all将在所有你的执行完毕后运行。 var promises = []; for(i=1, i<5, i++){ // singlePromise - this is now a new promise from the resulting then var singlePromise = SomeSevice.getData().then(function(data){ ...
  • Rakudo默认启用autoflush; 规范没有提到默认值。 Rakudo enables autoflush by default; the specification is silent about the default.
  • 我觉得奇怪的是返回的结构会像那样改变。 是的,jQuery在这里非常不一致。 当你将一个参数传递给$.when ,它会尝试将它转换为一个promise,当你传递多个它时,它突然试图等待所有这些并合并它们的结果。 现在抛出jQuery promises可以解决多个值(参数),并为此添加一个特例 。 所以我可以推荐两种解决方案: 完全丢弃$.when然后使用Promise.all而不是它: var promises = []; for (var p of recipients) { … prom ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)