using convert.inp to read data in

posts related to the RMark library, which may not be of general interest to users of 'classic' MARK

using convert.inp to read data in

Postby cjoos » Wed Aug 19, 2015 5:39 pm

I'm sorry for such a basic question but I am having a heck of a time getting convert.inp to read my .inp file. I inherited a complex and large dataset with 1 group factor with 5 levels and 62 covariates. I have broken it down to just the encounter history and the group variable column.

Here is my code
bevi <- convert.inp('bevi_group_nofreq', group.df = data.frame(eco = c('oh','cip','ecp','ip','irvh')))

and a sample of the data

/*ch OH CIP ECP IP IRVH*/
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00010 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0
00000.....00000 1 0 0 0 0

The group variable was originally coded as a dummy variable like this and when I run it this way I get the error

Error in `row.names<-.data.frame`(`*tmp*`, value = c("1:1", "1:2", "1:3", :
invalid 'row.names' length


If I add in a freq column I get this error

Error in convert.inp("bevi_eco", group.df = data.frame(eco = c("oh", "cip", :
Number of columns in data file does not match group/covariate specification


So to match the example dataset I changed the way the group was arranged to a column "eco" with all the values below like this both with and without the freq column.

/*ch freq eco*/
000000000000000 1 oh
000000000000000 1 oh
000000000000000 1 oh
000000000000000 1 oh
000010000000000 1 oh
000000010000000 1 oh

I get this error.
Error in convert.inp("bevi_eco_long", group.df = data.frame(eco = c("oh", :
Number of columns in data file does not match group/covariate specification


I have double checked the data set to make sure I only have those 5 values for eco, no blanks or typos. I am just at a loss for why this won't work. I have consulted others who know R very well but not Rmark and gone as far as I can troubleshooting this on my own. Please help!

Do I even need to use convert.inp or can I get my data in another way using base R to re-structure the data correctly?
cjoos
 
Posts: 5
Joined: Tue Aug 18, 2015 4:59 pm

Re: using convert.inp to read data in

Postby jlaake » Wed Aug 19, 2015 6:33 pm

convert.inp is used to convert an inp file that was used to construct the MARK dbf file. What you have listed doesn't have a ; at the end of the line so it isn't a MARK .inp file. Even though you think of them as coded dummy variables they are frequencies with a value of 1.

If you change to the second format you showed, then you shouldn't use convert.inp. Instead you should use import.chdata function or some other read function in R. If you do the latter, make sure that the ch field is read in as character and your eco field as a factor variable.

--jeff
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: using convert.inp to read data in

Postby cjoos » Thu Aug 20, 2015 11:40 am

I guess the other step I should have mentioned is that I tried these with and without the semicolons and it still did not work.
cjoos
 
Posts: 5
Joined: Tue Aug 18, 2015 4:59 pm

Re: using convert.inp to read data in

Postby cjoos » Thu Aug 20, 2015 12:13 pm

So when I run this code
bevi <- convert.inp('data set name', group.df = data.frame(eco = c('oh','cip','ecp','ip','irvh')))

with this data, which is the same as the first example with a column of semi-colons at the end like this
/*ch OH CIP ECP IP IRVH*/
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00010 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;
00000.....00000 1 0 0 0 0 ;

I get this message which is the same as when I didn't have the semi-colons

Error in `row.names<-.data.frame`(`*tmp*`, value = c("1:1", "1:2", "1:3", :
invalid 'row.names' length[/i]

I reran with the eco field in long format with the column of semi-colons and received the same message as without the semi-colons again.
cjoos
 
Posts: 5
Joined: Tue Aug 18, 2015 4:59 pm

Re: using convert.inp to read data in

Postby jlaake » Thu Aug 20, 2015 12:26 pm

The following works fine with convert.inp and bevi.inp and with import.chdata and bevi.txt.

Code: Select all
bevi <- convert.inp("bevi",group.df = data.frame(eco = c('oh','cip','ecp','ip','irvh')))
bevi

bevi <- import.chdata("bevi.txt",field.types=c("n","f"))
bevi



You can get those files from following links.

[url]
https://drive.google.com/file/d/0B77g1S ... sp=sharing
[/url]

[url]
https://drive.google.com/file/d/0B77g1S ... sp=sharing
[/url]

My guess is that you don't have the formats correct. The .inp file has space delimited fields. The .txt file for import.chdata can be either tab or space delimited. I always use tab delimited. Make sure there are no blank lines at the end of the files. That can screw up the functions.

If you use the RMark format for data entry (bevi.txt) then you can use any read function in R as long as you make sure the ch is read in as character and not as a factor or numeric. If you have a .inp file that was used with MARK it will work directly with convert.inp as long as you specify the arguments correctly. There are a number of examples of convert.inp you can find at ?convert.inp. The .inp files are in the RMark subdirectory of the R Library. The same is true for ?import.chdata and files are in same place.

--jeff
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: using convert.inp to read data in

Postby cjoos » Thu Aug 20, 2015 12:57 pm

I used that exact code you pasted and the exact data set you sent to link to cut and pasted into Notepad++ and saved as a txt file, then went in and changed the extension to .inp like I do when I create .inp datasets for MARK.

It does not work for me and I get this error which is pretty much what I get when I run the same code on the whole dataset. I went into the dataset with Notepad++ and changed all the tabs to spaces and it did not fix anything. I do not have an extra line at the end.

Error in convert.inp("test", group.df = data.frame(eco = c("oh", "cip", :

Number of columns in data file does not match group/covariate specification
In addition: Warning message:
In readLines(inp.filename) : incomplete final line found on 'test.inp'

Here is the code and a link to the full dataset. I am using the same code and the same data with the very short data sample and it works for you but not for me. I don't understand.

bevi <- convert.inp('bevi', group.df = data.frame(eco = c('oh','cip','ecp','ip','irvh')))


https://drive.google.com/folderview?id= ... sp=sharing
cjoos
 
Posts: 5
Joined: Tue Aug 18, 2015 4:59 pm

Re: using convert.inp to read data in

Postby cooch » Thu Aug 20, 2015 1:09 pm

cjoos wrote:I used that exact code you pasted and the exact data set you sent to link to cut and pasted into Notepad++ and saved as a txt file, then went in and changed the extension to .inp like I do when I create .inp datasets for MARK.

It does not work for me and I get this error which is pretty much what I get when I run the same code on the whole dataset. I went into the dataset with Notepad++ and changed all the tabs to spaces and it did not fix anything. I do not have an extra line at the end.

Error in convert.inp("test", group.df = data.frame(eco = c("oh", "cip", :

Number of columns in data file does not match group/covariate specification
In addition: Warning message:
In readLines(inp.filename) : incomplete final line found on 'test.inp'

Here is the code and a link to the full dataset. I am using the same code and the same data with the very short data sample and it works for you but not for me. I don't understand.

bevi <- convert.inp('bevi', group.df = data.frame(eco = c('oh','cip','ecp','ip','irvh')))


https://drive.google.com/folderview?id= ... sp=sharing


I just looked at the .inp file you posted. There were a couple of spacer characters (which MARK, RMark will both choke on) in the first two lines. I have tools which converted them to ASCII spaces, which I suspect would solve all the problems.
cooch
 
Posts: 1652
Joined: Thu May 15, 2003 4:11 pm
Location: Cornell University

Re: using convert.inp to read data in

Postby jlaake » Thu Aug 20, 2015 1:10 pm

You are mixing up the files. The format of the file at the link is in the format for import.chdata except that it shouldn't have the ; at the end. That is not a MARK format which with the eco value specified. That is an RMark format except that you added the ; which it should not have. The MARK format is used with convert.inp and the RMark format is used with import.chdata.

If you have any further issues with this, contact me offlist so we don't bother everyone on the list with this.
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: using convert.inp to read data in

Postby cooch » Thu Aug 20, 2015 1:14 pm

cooch wrote:
cjoos wrote:I used that exact code you pasted and the exact data set you sent to link to cut and pasted into Notepad++ and saved as a txt file, then went in and changed the extension to .inp like I do when I create .inp datasets for MARK.

It does not work for me and I get this error which is pretty much what I get when I run the same code on the whole dataset. I went into the dataset with Notepad++ and changed all the tabs to spaces and it did not fix anything. I do not have an extra line at the end.

Error in convert.inp("test", group.df = data.frame(eco = c("oh", "cip", :

Number of columns in data file does not match group/covariate specification
In addition: Warning message:
In readLines(inp.filename) : incomplete final line found on 'test.inp'

Here is the code and a link to the full dataset. I am using the same code and the same data with the very short data sample and it works for you but not for me. I don't understand.

bevi <- convert.inp('bevi', group.df = data.frame(eco = c('oh','cip','ecp','ip','irvh')))


https://drive.google.com/folderview?id= ... sp=sharing


I just looked at the .inp file you posted. There were a couple of spacer characters (which MARK, RMark will both choke on) in the first two lines. I have tools which converted them to ASCII spaces, which I suspect would solve all the problems.


More specifically, you have some tab characters that do not show up when you use Notepad++. To convert all tab characters (visible, or not) to spaces, simply go to Edit | Blank operation | Tab to space.
cooch
 
Posts: 1652
Joined: Thu May 15, 2003 4:11 pm
Location: Cornell University

Re: using convert.inp to read data in

Postby cjoos » Thu Aug 20, 2015 2:10 pm

Oh my COOCH you are a life saver! Thank you so much! That fixed the problem on the abbreviated dataset and the full one with 62+ columns of covariates. I even had done a find replace with Tabs and spaces because I didn't know about that tool and that didn't fix it. I did convert Tabs to spaces and then spaces back to Tabs and all seems well.

On to the next!
cjoos
 
Posts: 5
Joined: Tue Aug 18, 2015 4:59 pm

Next

Return to RMark

Who is online

Users browsing this forum: No registered users and 1 guest

cron