首页 \ 问答 \ 从read.csv(file.choose())获取文件名(Get filename from read.csv(file.choose( )))

从read.csv(file.choose())获取文件名(Get filename from read.csv(file.choose( )))

我想知道是否可以从read.csv调用中嵌入的file.choose()命令中提取文件名。 现在我分两步来做,但用户必须选择同一个文件两次,以便提取数据(csv)和文件名,以便在我运行的函数中使用。 我想这样做,所以用户只需要选择一次文件,然后我就可以同时使用数据和文件名。

以下是我正在处理的内容:

data <- read.csv(file.choose(), skip=1))
name <- basename(file.choose())

如果有帮助,我正在运行OS X,因为我认为file.choose()具有不同的行为,具体取决于操作系统。 提前致谢。


I'm wondering if it would be possible to draw out out the filename from a file.choose() command embedded within a read.csv call. Right now I'm doing this in two steps, but the user has to select the same file twice in order to extract both the data (csv) and the filename for use in a function I run. I want to make it so the user only has to select the file once, and then I can use both the data and the name of the file.

Here's what I'm working with:

data <- read.csv(file.choose(), skip=1))
name <- basename(file.choose())

I'm running OS X if that helps, since I think file.choose() has different behavior depending on the OS. Thanks in advance.


原文:https://stackoverflow.com/questions/9233471
更新时间:2021-07-10 11:07

最满意答案

在(引用)表vulling您需要为外键设置vulling值。 但你没有。 你有三元组(vulling, put, spoor)独特价值,这些价值并不代表对的唯一性(spoor, vulling)

考虑

vulling
======================
vulling | put | spoor
----------------------
1       | 0   | 0
1       | 1   | 0

这两排在三联体方面是vulling ,而不是一对vullingvulling 。 最后,您应该在表定义中添加UNIQUE(vulling, spoor) ,或者使用helper-table管理多对多关系。

或者你可以反转外键def:

ALTER TABLE vulling
ADD FOREIGN KEY (spoor,vulling)
REFERENCES put_25_vlak_1_spoor(spoor,vulling);

On (referenced) table vulling you need to have uniqe values for your foreign key. But you don't. You have unique values for triplet (vulling, put, spoor) which not nessecerly mean uniqness of pair (spoor, vulling).

Consider

vulling
======================
vulling | put | spoor
----------------------
1       | 0   | 0
1       | 1   | 0

That two rows are uniqe in terms of triplet but not as a pair of vulling and spoor. In the end you should either add UNIQUE(vulling, spoor) to your table definition, or manage many-to-many relation using helper-table.

Alternatively you may reverse te foreign key def:

ALTER TABLE vulling
ADD FOREIGN KEY (spoor,vulling)
REFERENCES put_25_vlak_1_spoor(spoor,vulling);

相关问答

更多
  • 一般来说,事前测试不是一个好主意,因为它要求您显式锁定表以防止其他客户端在测试和插入之间更改或插入数据。 显式锁定对并发性有害。 通过失败的插入自动递增的序列通常不是问题。 只是不要假设插入数据库的值是连续的。 数据库和obj-c是两个完全不同的东西。 让数据库检查问题,更容易向模式添加适当的约束,然后检查客户端程序中的所有内容。 默认是回滚到事务的开始。 但您可以使用保存点控制它并回滚到保存点。 但是,CTE是查询的一部分,并且当部分查询失败时,查询总是完全回滚。 但是,您可以通过将CTE拆分为创建临时表 ...
  • SQLite命令添加一个名为myconstraint的列,没有数据类型,列约束CHECK a != b (需要括号才有效)。 SQLite的ALTER TABLE无法添加表约束。 ( 替代方案更不便携。) The SQLite command adds a column named myconstraint, with no data type, and a column constraint CHECK a != b (which needs parentheses to be valid). SQLit ...
  • 如果您发布错误消息,这将有所帮助。 但我想你只是错过了圆括号: ALTER TABLE my_table ADD CONSTRAINT my_fk FOREIGN KEY (my_field) REFERENCES my_foreign_table ON DELETE CASCADE; It would help if you posted the error message. But I think you are just missing the parenthesis: ALTER TABL ...
  • 您尝试链接到尚不存在的产品和kaart。 移动: INSERT INTO kaart_product VALUES (1,1); 下两行: INSERT INTO product VALUES ('studentenproduct',1); 那应该为你做的工作。 尝试搜索谷歌的forgein关键约束及其工作原理。 You try to link to a product and a kaart that doesn't exist yet. Move: INSERT INTO kaart_product ...
  • t_property_landlord.landlord_id不是唯一列。 它需要是外键才能引用它。 有关如何声明一个的信息,请参阅此处: https : //www.postgresql.org/docs/8.1/static/ddl-constraints.html 您的t_property_landlord表应如下所示: create table if not exists t_property_landlord( landlord_id BIGSERIAL UNIQUE NOT NULL, ...
  • 也许你应该向导入工具生产者提出这个问题。 暂时禁用约束没有简单的方法; 你必须自己放弃并重新创建它们。 查看输出pg_dump --section=post-data应该会有所帮助,因为它包含了在末尾创建所有约束的命令。 Maybe you should raise this issue with the import tool producers. There is no simple way to temporarily disable constraints; you'd have to drop a ...
  • 你宣布了这种关系: FOREIGN KEY(sectionNumber) REFERENCES Sections(sectionNumber) sectionnumber未声明为唯一。 您需要修复数据结构或使用主键。 You have this relationship declared: FOREIGN KEY(sectionNumber) REFERENCES Sections(sectionNumber) sectionnumber is not declared to be unique. Yo ...
  • 要动态删除和重新创建外键约束,可以将其全部包装在函数中或使用DO命令: DO $body$ DECLARE _con text := ( SELECT quote_ident(conname) FROM pg_constraint WHERE conrelid = 'myschema.mytable'::regclass AND confrelid = 'myschema.myreftable'::regclass LIMIT 1 ...
  • 另一个表,具有多个唯一索引: create table utest(id integer, position integer not null, unique(id, position)); test=# \d utest Table "public.utest" Column | Type | Modifiers ----------+---------+----------- id | integer | position | integer | not nu ...
  • 在(引用)表vulling您需要为外键设置vulling值。 但你没有。 你有三元组(vulling, put, spoor)独特价值,这些价值并不代表对的唯一性(spoor, vulling) 。 考虑 vulling ====================== vulling | put | spoor ---------------------- 1 | 0 | 0 1 | 1 | 0 这两排在三联体方面是vulling ,而不是一对vulling和vulling ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。