simsem / semTools

Useful tools for structural equation modeling
75 stars 36 forks source link

clipboard() error when what="summary" #56

Closed dmaltschul closed 1 year ago

dmaltschul commented 5 years ago

Hello, Across a few different machines using the lavaan examples, I've noticed that clipboard() and saveFile() give an error when the 'what' argument is left as the default, "summary". Summary is unfortunately just what I'd like to get.

The error is Error in is.data.frame(x) : argument "x" is missing, with no default

If I change 'what' to be something else like "coef" or "fit" it works fine. Any ideas if this is something that can be fixed in the environment or the function itself?

TDJorgensen commented 5 years ago

Sunthud wrote this function many operating systems ago, so I am unlikely to figure out the problem anytime soon. I'm getting errors on my Mac about pbcopy not working and xclip not being installed (but it's a Linux program...). You could just use the heart of the saveFile() function to write the output to a text file.

example(cfa)
write(paste(utils::capture.output(summary(fit)),
            collapse = "\n"), file = "foo.txt")
dmaltschul commented 5 years ago

Thanks, that is helpful. Keeping the columns separated by tabs was very useful for making TSV exports, so the best work around I've found today was using " as.data.frame(unclass(parameterEstimates(...))) ". Once every item has its own df column, the whole "summary" is easy to work with.

TDJorgensen commented 5 years ago

If you also want the pretty output from summary(), you can add the argument parameterEstimates(..., add.attributes = TRUE).

josephollier commented 1 year ago

I am having this issue on both Windows and Mac with semTools_0.5-6. Summary doesn't work, but nor do coef or other calls. Is there any fix yet?

TDJorgensen commented 1 year ago

I have spent way too much time trying to figure this problem out. If you can find a solution, let me know. Otherwise, I am deprecating these functions and eventually removing them.

sfcheung commented 1 year ago

I am not familiar with this function. Learned about it just now from GitHub notification. Maybe the following change can solve at least the clipboard() error when what="summary"?

https://github.com/sfcheung/semTools/commit/c8e61ad3bfb8445026e18eb90542a8fad176b594

The error occur here

https://github.com/sfcheung/semTools/blob/c8e61ad3bfb8445026e18eb90542a8fad176b594/semTools/R/clipboard.R#L188-L190

At this point, with what = "summary", the content has already been saved by copySummary() and writeArgs$x is not set.

The task has already finished when calling copySummary(). Therefore, adding return() seems to be able to solve the error:

https://github.com/sfcheung/semTools/blob/c8e61ad3bfb8445026e18eb90542a8fad176b594/semTools/R/clipboard.R#L142-L150

sfcheung commented 1 year ago

Oh ... I am not aware that tab is used in the file. I used whitespace, hence the odd alignment.

TDJorgensen commented 1 year ago

adding return() seems to be able to solve the error

That did not resolve the problem for me. However, your explanation made sense. I updated the hidden saveFileLavaan() function to return the updated writeArgs arguments, rather than doing the writing itself. This resolved the problem on my Mac. I need to check it on a Windows computer, but I hope this resolves this issue for good. Thanks @sfcheung for the inspiration!

TDJorgensen commented 1 year ago

looks like it is working pretty well at this point. There are some alignment issues I noticed in the help-page example, which only seem to show up when a subset (some, but not all) of parameters are labeled in the model syntax, so it makes an "extra" column when pasting into Excel. The saveFile() function appears safer in this scenario.